I am trying to get the profile and username in JavaScript button but I am getting an error when trying to click on the button


var currentuser = sforce.connection.getUserInfo();

if('{!Contract_Approval_Form__c.Approval_Status__c}' == 'Approved')
if('{!$User.Id}' == '005E00000088akt')
 window.open("/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Contract_Approval_Form__c.Id}&templateId=aH0V0000000CcVSKA0 ","_self"); 
}else if('{!$User.Id}' == '005E0000001noF2IAI')
 window.open("/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Contract_Approval_Form__c.Id}&templateId=aH0V00000008PXg ","_self"); 
}else if('{!$Profile.Id}' == '00eE0000000eOCd')
{!Contract_Approval_Form__c.Id}&templateId=aH0V00000008PXl ","_self"); 
window.alert("Please make sure Approval Status to be Approved");

When ever I add else if('{!$Profile.Id}' == '00eE0000000eOCd') condition , button is failing .Can you please let me know what I am missing

Error when user clicks on button

  • 1
    Can you update your question and provide the error that you are receiving? Dec 7 '18 at 20:34
  • Hi @John Towers : I updated the question with the error. Can you please let me know what I am missing in profile name Dec 10 '18 at 17:57

Your primary problem is that normal strings don't allow line breaks:

{!Contract_Approval_Form__c.Id}&templateId=aH0V00000008PXl ","_self"); 

This should fix your main problem:

window.open("/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Contract_Approval_Form__c.Id}&templateId=aH0V00000008PXl ","_self"); 

As a side note, due to the possibility of script injection, you should prefer to use either JSENOCDE or do formula-based evaluation.

For example:




Note that the if statement simply renders as if(true) or if(false), so no quotes are needed around the merge field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.