Skip to main content
Hi,

I am trying to create a custom button on a custom object which can only be clicked if a date on the parent oject is filled in.  I am new to SOQL and javascript but have managed to created custom buttons in the past with validation rules which related to the object they are on however I am struggling with cross object rules.

In this instance an Assessment__c can only be submitted if it's parent Referral__c has an accepted date that is not blank.

Any help would be very much apprecitated.

Here is the code so far:

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

{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var ReferraAccepted = "SELECT Accepted_date__c FROM Referral__c WHERE Name = '{!Assessment__c.Referral__c}' LIMIT 1";

if (ReferraAccepted == null){alert ("Please submit the completed referral form to the Clearing House as this form cannot be submitted on it's own.")} 

else {

var newRecords = []; 

var c = new sforce.SObject("Assessment__c"); 

c.id ="{! Assessment__c.Id }"; 

c.Submit_for_assessment__c = true; 

newRecords.push(c); 

result = sforce.connection.update(newRecords); 

window.location.reload();

}

 
19 respuestas
  1. 14 jul 2015, 10:29

    Hi Mike,

    Try this code -->>

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

    {!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 

    var ReferraAccepted = sforce.connection.query("SELECT Referral__r.Accepted_Date__c from Assessment__c where id ='{!Assessment__c.Id}' limit 1");

    records = ReferraAccepted.getArray("records"); 

    var accDate = records[0].Referral__r.Accepted_Date__c; 

    if(accDate==null){ 

    alert("Please submit the completed referral form to the Clearing House as this form cannot be submitted on it's own.") 

    else { 

    var newRecords = []; 

    var c = new sforce.SObject("Assessment__c"); 

    c.id ="{!Assessment__c.Id }"; 

    c.Submit_for_assessment__c = true; 

    newRecords.push(c); 

    result = sforce.connection.update(newRecords); 

    window.location.reload(); 

    }

    Let me  know if this works for you..!!

     
Cargando
0/9000