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
Ranadheer chRanadheer ch 

How to Add Relation ship field Id to javascript Button

How to Add Relation ship field Id to javascript Button...For Example:  Account Address(Account_Address__c) Object. In this object i have a Account__C( field) value Which has a Master Detail Relation ship with Account. 


Now created a Javascript Button on Account_Address__C detail page . nOw my requirement is i have to send Account_Address_Id  and Account__c.Id Through this button ...How can i do that Please help me ...i ried the below code

Button:


{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 
//alert('hi'); 
if('{!Account_Address__c.Id}'!= null) 

alert('Do You Want To Create A SAP Account'); 
var AcctAddressID='{!Account_Address__c.Id}';
Var AccountID='{!Account_Address__c.Account__c.ID}' 
sforce.apex.execute("Bandvidth CreateUpdateSAPAccountAddress","createupdateSAPAccountAddress",{AcctAddressID:"{!Account_Address__c.Id}",{AccountID:"{!Account_Address__c.Account__c.ID}}); 
}


Am getting below Error while saving the button:

Error: Field Account_Address__c.Account__c.ID does not exist. Check spelling.


Please help me..thanks








 
Best Answer chosen by Ranadheer ch
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Ranadheer ch:

 currently salesforce do not support use of related objects fields as merge fields in JavaScript, instead you would need to query first, fetch the result and then pass it, for eg.,


var result = sforce.connection.query("SELECT id from Account__c where name LIKE '{!Account__c}' '");

// And then fetch the value from there 

OR

Since you were anyway using method, get only addressid and query rest of the details in the method itsself 

OR

Create a formula field in Account Address which has AccountId value and then just refer that field in the javascript.


you can choose either of the above

Thanks,
balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Ranadheer ch:

 currently salesforce do not support use of related objects fields as merge fields in JavaScript, instead you would need to query first, fetch the result and then pass it, for eg.,


var result = sforce.connection.query("SELECT id from Account__c where name LIKE '{!Account__c}' '");

// And then fetch the value from there 

OR

Since you were anyway using method, get only addressid and query rest of the details in the method itsself 

OR

Create a formula field in Account Address which has AccountId value and then just refer that field in the javascript.


you can choose either of the above

Thanks,
balaji
This was selected as the best answer
Ranadheer chRanadheer ch
Thankd for ur help balaji...I Created a Fomula filed Which is populating the Account Id field Name like Account_ID__c...then i modified the code ...saved the button ...after this am getting an following  error while i click on that button

After I click on button 


Error:Fault Code No such parameter defined for the Opration Error

My Modified Code:


{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 
//alert('hi'); 
if('{!Account_Address__c.Id}'!= null) 

alert('Do You Want To Create A SAP Account'); 
var AcctAddressID='{!Account_Address__c.Id}';
var accountID='{!Account_Address__c.Account_ID__c}';

sforce.apex.execute("SandvineCreateUpdateSAPAccount","createupdateSAPAccount",{AcctAddressID: "{!Account_Address__c.Id}",accountID:"{!Account_Address__c.Account_ID__c}"}); 

 
}




 
Balaji Chowdary GarapatiBalaji Chowdary Garapati
Can you share your createupdateSAPAccount method too? Just to confirm if you have two parameters for the method in the same order!!

Thanks,
Balaji
Ranadheer chRanadheer ch
Hi Balaji..problem solved  with your formula field idea ...Thanks