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
sales4cesales4ce 

Java Script Error

Hi,

 

I have a custom button which has "Onclick" execute java script.

I am looking at the status of a field and then redirecting the user appropriately.

But i am encountering an error, which i am unable to figure out.

 

if({!Opportunity.StageName}=='Prospecting')

{

 alert('You cannot perform action');

}

 

else

{

 

&serverUrl={!API.Partner_Server_URL_80}
&id={!Opportunity.Id}
&reportid=00O600000023k2f?pv0={!Opportunity.Id}
&reportid=00O600000023k2k?pv0={!Contact.Id}
&reportid=00O600000023k3O?pv0={!Opportunity.Id}
&reportid=00O600000023k3T?pv0={!Opportunity.Id}
&reportid=00O600000023qu9?pv0={!Opportunity.Id}
&ESVisible=1
&ESAgreementName={!Opportunity.Name}
&ESSignatureType=2
&TemplateId={!IF ( Opportunity.RecordTypeId = "012600000005Eso", IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000004z7sv" , "a0G60000004z7t0" ) , IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000003Zej9" , "a0G60000003ZejE" ) )}
&ds4={!IF( $Profile.Name = "System Administrator", "0", "1")}
&ds7={!IF( $Profile.Name = "System Administrator", "0", "4")}

window.location.href="https://www.appextremes.com/apps/Conga/PointMerge.aspx?sessionId={!API.Session_ID}&serverUrl={!API.Partner_Server_URL_80}&id={!Opportunity.Id}&reportid=00O600000023k2f?pv0={!Opportunity.Id}&reportid=00O600000023k2k?pv0={!Contact.Id}&reportid=00O600000023k3O?pv0={!Opportunity.Id}&reportid=00O600000023k3T?pv0={!Opportunity.Id}&reportid=00O600000023qu9?pv0={!Opportunity.Id}&ESVisible=1&ESAgreementName={!Opportunity.Name}&ESSignatureType=2&TemplateId={!IF ( Opportunity.RecordTypeId = "012600000005Eso", IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000004z7sv" , "a0G60000004z7t0" ) , IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000003Zej9" , "a0G60000003ZejE" ) )}&ds4={!IF( $Profile.Name = "System Administrator", "0", "1")}&ds7={!IF( $Profile.Name = "System Administrator", "0", "4")}";

 

}

 

 

The error is:

 

 

A problem with the OnClick JavaScript for this button or link was encountered:

missing ) after condition.

 

 

It seems to me correct. i do not know what i am missing. can anyone help me here?

 

Thanks,

Sales4ce

 

.

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

Use window.open( "https://www.appextremes.com/apps/Conga/PointMerge.aspx?sessionId={!API.Session_ID}&serverUrl={!API.Partner_Server_URL_80}&id={!Opportunity.Id}&reportid=00O600000023k2f?pv0={!Opportunity.Id}&reportid=00O600000023k2k?pv0={!Contact.Id}&reportid=00O600000023k3O?pv0={!Opportunity.Id}&reportid=00O600000023k3T?pv0={!Opportunity.Id}&reportid=00O600000023qu9?pv0={!Opportunity.Id}&ESVisible=1&ESAgreementName={!Opportunity.Name}&ESSignatureType=2&TemplateId={!IF ( Opportunity.RecordTypeId = "012600000005Eso", IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000004z7sv" , "a0G60000004z7t0" ) , IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000003Zej9" , "a0G60000003ZejE" ) )}&ds4={!IF( $Profile.Name = "System Administrator", "0", "1")}&ds7={!IF( $Profile.Name = "System Administrator", "0", "4")} ");

 

Let me know if you face any issues.

All Answers

SargeSarge

Hi,

 

 

     I think you need to enclose {!Opportunity.StageName} with single quotes in 'IF" condition.

Imran MohammedImran Mohammed

Just add single quotes and it should resolve the issue. 

Replace if({!Opportunity.StageName}=='Prospecting') with  if( '{!Opportunity.StageName}' == 'Prospecting')

 

sales4cesales4ce

That definitely helped me sole one problem, but it created a new problem.

 

In the else part i am trying to navigate the user to a different URL.

 

How can i open it in a new window. 

 

 

&serverUrl={!API.Partner_Server_URL_80}
&id={!Opportunity.Id}
&reportid=00O600000023k2f?pv0={!Opportunity.Id}
&reportid=00O600000023k2k?pv0={!Contact.Id}
&reportid=00O600000023k3O?pv0={!Opportunity.Id}
&reportid=00O600000023k3T?pv0={!Opportunity.Id}
&reportid=00O600000023qu9?pv0={!Opportunity.Id}
&ESVisible=1
&ESAgreementName={!Opportunity.Name}
&ESSignatureType=2
&TemplateId={!IF ( Opportunity.RecordTypeId = "012600000005Eso", IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000004z7sv" , "a0G60000004z7t0" ) , IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000003Zej9" , "a0G60000003ZejE" ) )}
&ds4={!IF( $Profile.Name = "System Administrator", "0", "1")}
&ds7={!IF( $Profile.Name = "System Administrator", "0", "4")} " ;

 

window.location.href= "https://www.appextremes.com/apps/Conga/PointMerge.aspx?sessionId={!API.Session_ID}&serverUrl={!API.Partner_Server_URL_80}&id={!Opportunity.Id}&reportid=00O600000023k2f?pv0={!Opportunity.Id}&reportid=00O600000023k2k?pv0={!Contact.Id}&reportid=00O600000023k3O?pv0={!Opportunity.Id}&reportid=00O600000023k3T?pv0={!Opportunity.Id}&reportid=00O600000023qu9?pv0={!Opportunity.Id}&ESVisible=1&ESAgreementName={!Opportunity.Name}&ESSignatureType=2&TemplateId={!IF ( Opportunity.RecordTypeId = "012600000005Eso", IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000004z7sv" , "a0G60000004z7t0" ) , IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000003Zej9" , "a0G60000003ZejE" ) )}&ds4={!IF( $Profile.Name = "System Administrator", "0", "1")}&ds7={!IF( $Profile.Name = "System Administrator", "0", "4")} " ;

 

Its raising another error:

 

 

A problem with the OnClick JavaScript for this button or link was encountered:

unterminated string literal

 

 

Any Idea/pointers?

 

Thanks,

Sales4ce

Imran MohammedImran Mohammed

Use window.open( "https://www.appextremes.com/apps/Conga/PointMerge.aspx?sessionId={!API.Session_ID}&serverUrl={!API.Partner_Server_URL_80}&id={!Opportunity.Id}&reportid=00O600000023k2f?pv0={!Opportunity.Id}&reportid=00O600000023k2k?pv0={!Contact.Id}&reportid=00O600000023k3O?pv0={!Opportunity.Id}&reportid=00O600000023k3T?pv0={!Opportunity.Id}&reportid=00O600000023qu9?pv0={!Opportunity.Id}&ESVisible=1&ESAgreementName={!Opportunity.Name}&ESSignatureType=2&TemplateId={!IF ( Opportunity.RecordTypeId = "012600000005Eso", IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000004z7sv" , "a0G60000004z7t0" ) , IF ( ISPICKVAL ( Opportunity.Payment_Methond__c , "Credit Card" ) , "a0G60000003Zej9" , "a0G60000003ZejE" ) )}&ds4={!IF( $Profile.Name = "System Administrator", "0", "1")}&ds7={!IF( $Profile.Name = "System Administrator", "0", "4")} ");

 

Let me know if you face any issues.

This was selected as the best answer
sales4cesales4ce

Thanks Imran! It worked for me.

 

Sales4ce