+ Start a Discussion
Peter van HeckPeter van Heck 

Pass field value from custom object

My custom object "Locations" has a Master-Detail Relationship
with "Accounts", so when I override the "New Location" button
with the S-Control:
Test1: {!Account.Name}

 and I click "New Location" in "Accounts", it shows:
Test1: Heckwork
So far so good.
My custom object "Systems" also has a Master-Detail relation
with "Accounts" AND a Lookup Relationship with "Locations".
When I override the "New System" button  with this S-Control:
Test2: {!Location__c.Name__c}

and I click "New System" in "Locations", it shows:
Does anyone know why it does not show the value from the
"Locations" "Name" field?

Message Edited by Peter van Heck on 09-26-2008 10:26 AM
The difference between the two is that the 'object context' (for lack of a better word) does not get passed in to the document context with lookup relationships, as it does with M-D relationships. You'd have to do a SOQL query to get the name of the Location__c field. Something like this:

var locIdStr = "{!Location__c}";
var query = "SELECT Name__c FROM Location__c WHERE Id = '{!Location__c}'"; var result = sforce.connection.query(query); var record = result.getArray("records"); var locName = record[0].Name__c;
Note the error prevention in case location is not specified.

If you were going to dot through like this on a custom field, you'd do {!Location__r.Name__c} anyway.