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
Rachel BrozinickRachel Brozinick 

Pulling Account Fields with Javascript button

I have a DocuSign Button I am creating.  My client is sending from the Opportunity.  I want to be able pull a field called Dedicated_CS_Rep__c from the account related to that Opportunity.  Dedicated_Rep__c is a lookup field from the User.   Here's my code:

function getDedicatedCSRep (oppId) { 
var result = sforce.connection.query("select Opportunity.Id, Account.Name, Account.Dedicated_CS_Rep__c from Opportunity where Id = '" + oppId + "' "); 

if(!result || result['size'] != 1) { 
return null; 
} 

var AccountRep = result.getArray('records')[0]; 

return AccountRep.Opportunity; 
} 

var dedicatedContact = getDedicatedCSRep('{!Opportunity.Id}');

Whenever I try to send, i am getting this error:

User-added image

I did make sure there was a value listed on the Account that I was testing.  What am I missing?

Thanks!

Rachel
Ramu_SFDCRamu_SFDC
See if the below posts gives any clue

http://stackoverflow.com/questions/6550795/uncaught-typeerror-cannot-read-property-value-of-undefined
http://stackoverflow.com/questions/8004617/javascript-cannot-read-property-bar-of-undefined
Rachel BrozinickRachel Brozinick
I was pulling the wrong object over in the return.  My problem now is that I can pull the information from the User Record Now via the lookup.  It's saying my relationship doesn't exist.

function getDedicatedAccountRep (oppId) {
var result = sforce.connection.query("select Account.Id, Account.Dedicated_Rep__r.FirstName from Opportunity where Id = '" + oppId + "' ");

if(!result || result['size'] != 1) { 
	return null;
    }
    
    var DedRepRole = result.getArray('records')[0];

    return DedRepRole.Account;
}

var dedicatedRep = getDedicatedAccountRep('{!Opportunity.Id}');