function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Irish@accIrish@acc 

need help on custom button

HI,

I have a custom button which creates child record on metting some condition now I have got another requiremnt that it also creates grand child record..please help me on this a

s how to achieve this...below is my code...

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/27.0/apex.js")}
var url = parent.location.href;

var prjid='{!Project__c.Id}';

var TaskId='{!Task__c.Id}';


result = sforce.connection.query("Select Status__c,id,Project__c from Task__c where Status__c not in ('Complete','Cancelled') and Project__c='"+prjid +"'");



var records = result.getArray("records");
var date = new Date('{!TODAY()}'); 
var i = records.length;
if(i>0)
   {
    
 
   window.alert("All Tasks need to be completed before the project can be closed.");
   parent.location.href = url;
}
else{

var createqod = new sforce.SObject("Quality_of_delivery__c"); 
createqod.Project__c = "{!Project__c.Id}"; 
createqod.Name = "{!Project__c.Name} " +" - "+"FINAL";
//createqod.Approved_Status__c="Pending input from Dev Specialist";
createqod.Number_of_Change_Requests__c=0;
createqod.date__c=date;
createqod.Final__c="True";
createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";

sforce.connection.create([createqod]);

//creating Grand Child Record here

var createrc = new sforce.SObject("Root_cause__c"); 
//createrc.Name="Root Cause"+" - "+"Final";
createrc.Project_Name__c="{!Project__c.Id}";
createrc.TaskName__c=    //how to give value here this is the parent id of the grand child record
createrc.Apex_context__c="true";
createrc.Final__c="True";
createrc.Launch_date_delay__c=0;
createrc.date__C=date;
//createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";
sforce.connection.create([createrc]);



parent.location.href = url;

}

 

 

Irish@accIrish@acc

this code works fine which is creating child record...

var createqod = new sforce.SObject("Quality_of_delivery__c");
createqod.Project__c = "{!Project__c.Id}";
createqod.Name = "{!Project__c.Name} " +" - "+"FINAL";
//createqod.Approved_Status__c="Pending input from Dev Specialist";
createqod.Number_of_Change_Requests__c=0;
createqod.date__c=date;
createqod.Final__c="True";
createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";

sforce.connection.create([createqod]);

 

but this code which is suppose to create grand child records doesn't work at all

 

var createrc = new sforce.SObject("Root_cause__c");
//createrc.Name="Root Cause"+" - "+"Final";
createrc.Project_Name__c="{!Project__c.Id}";
createrc.TaskName__c=    //how to give value here this is the parent id of the grand child record
createrc.Apex_context__c="true";
createrc.Final__c="True";
createrc.Launch_date_delay__c=0;
createrc.date__C=date;
//createqod.Dev_Lead__c="{!Project__c.Dev_Lead_UserId__c}";
sforce.connection.create([createrc]);

Shiv ShankarShiv Shankar

Where is the field which holds the value for parent ??
you should do something like this

createrc.Quality_of_delivery__c = createqod.id;

 

Irish@accIrish@acc
one thing I haven't mentioned here ...the parent object is Project and it has two chils one is Qod and other is task now task has one child Root_Cause and this record I have to create....