Skip to main content

Trying to get lookup field value in JavaScript

I have a custom object named CPQ_Request_for_Proposal__c, which has a lookup(Text) value for Account__c.

I'm trying to code a button which will use the value of Account__c to get actual Account object. The first alert() comes up. However, my code keeps returning "Unexpected Identifier" before the second alert() appears. I'm new to using JavaScript in a Salesforce context. I'm sure I'm doing something simple wrong, but I haven't been able to figure it out after searching for an answer for a while. What am I doing wrong in my code?

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

// Visual hint to the user that the processing has started this.disabled = true; 
this.className = "btnDisabled";

var clientSite = new sforce.SObject("Client_Site__c");  
var rfpId = '{!CPQ_Request_for_Proposal__c.Id}';   
clientSite.RequestForProposal__c
= '{!CPQ_Request_for_Proposal__c.Id}';

alert ( 'RFP Id = ' + rfpId );

var accountId = '';

var accountId = '{!CPQ_Request_for_Proposal__c.Account__c}';

alert ( 'accountId = ' + accountId );
Michael Sobczak
  • 1.3k
  • 2
  • 20
  • 50