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
dgindydgindy 

Getting a Relationship Result

How do you get the results for a relationship?
 
Code:
var sql = "Select Doctor__r.OwnerId,Doctor__r.Name,Name,First_Name__c,Last_Name__c,Id  from Patient__c where Id = '" + records[i].get("Patient__c") + "' Limit 1";
         var patqr = sforce.connection.query(sql);

newCell.innerHTML = patqr.getArray("records")[0].get("Doctor__r.OwnerId");

 
I get a null. Should it be <Doctor__c> ???
jeremyfrey1jeremyfrey1
Try this instead:

Code:
var sql = "Select Doctor__r.OwnerId,Doctor__r.Name,Name,First_Name__c,Last_Name__c,Id  from Patient__c where Id = '" + records[i].get("Patient__c") + "' Limit 1";
var patqr = sforce.connection.query(sql);

var patient = patqr.records[0];
newCell.innerHTML = patient.Doctor__r.OwnerId;

 
The objects the ajax toolkit returns are, for lack of a better term in javascript, strongly typed.  I've written a few pieces of code similar to this and I've never had an issue.  Here's an example:

Code:
function formatAddress(contactObj)
{
    var address = contactObj.Account.BillingStreet + ' ' + contactObj.Account.BillingCity + ' ' + contactObj.Account.BillingState  + ' ' +  contactObj.Account.BillingPostalCode;
    return address;
}

 If this doesn't work for you then there's probably some other reason why you can't get at the related data.