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
SeniorMoveSeniorMove 

Use Detail Page button with Execute Javascript to pass values to related object?

This seems like it should be straightforward, but it doesn't work.  I don't receive any errors, but nothing happens.

 

The Move__c object is on the detail side of a Master-Detail relationship with Client__c.

 

I'm trying to use the button to grab field values from Move__c, and pass those values into fields on Client__c.

 

Am I trying to do something that won't work?

 

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

var connection = sforce.connection; 

var url = parent.location.href; //string for the URL of the current page 
var clientMoved = "{!Move__c.ClientId__c}"; 

var moveToStreet = "{!Move__c.Move_To_Street__c}"; 
var moveToCity = "{!Move__c.Move_To_City__c}"; 
var moveToState = "{!Move__c.Move_To_State_Province__c}"; 
var moveToZip = "{!Move__c.Move_To_Zip_Postal_Code__c}"; 
var moveToCountry = "{!Move__c.Move_To_Country__c}"; 
var moveToProperty = "{!Move__c.Property__c}";

var client= new sforce.SObject("Client__c"); 
client.Id = clientMoved; 

client.Mailing_Street__c = moveToStreet; 
client.Mailing_City__c = moveToCity; 
client.Mailing_State__c = moveToState; 
client.Mailing_Zip_Code__c = moveToZip; 
client.Mailing_Country__c = moveToCountry; 

client.Shipping_Street__c = moveToStreet; 
client.Shipping_City__c = moveToCity; 
client.Shipping_State__c = moveToState; 
client.Shipping_Zip_Code__c = moveToZip; 
client.Shipping_Country__c = moveToCountry; 

client.Property__c = moveToProperty;

connection.update([client]); 
parent.location.href = url; //refresh the page

 

Best Answer chosen by Admin (Salesforce Developers) 
jackeejackee

you can pass the value using the URL ;

 

/e?clone=1&retURL=%2F0034000000jO8s0&field1=data&field2=data

All Answers

jackeejackee

you can pass the value using the URL ;

 

/e?clone=1&retURL=%2F0034000000jO8s0&field1=data&field2=data

This was selected as the best answer
SeniorMoveSeniorMove

Thanks jackee.  I always seem to forget about the URL method.  I guess I had moved away from that because I thought Salesforce was going to deprecate the ability to do that.

 

I also found the following link helpful:

 

http://salesforce.phollaio.com/2007/01/11/salesforces_url_structure/

 

Thanks again!