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
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:
Code:
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:
Code:
Test2: {!Location__c.Name__c}

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


Message Edited by Peter van Heck on 09-26-2008 10:26 AM
cgosscgoss
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:

Code:
var locIdStr = "{!Location__c}";
if(locIdStr.length>0){
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.