Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a created a custom button using Onclick Javascript action.

I have a custom picklist field on Opportunity; I am just checking the value selected for this field on click of this button.

If the value is X or Y or Z then it should stay in the same page with an alert message,else it should take them to a different site.

The below script works perfectly, but when I click this button on opportunities in which the opportunity name has double quotes then it throws the below error:

missing ) after argument list

e.g: " N "Third Avenue (Opportunity name)

Can anyone please assist me in trouble shooting and a workaround..

Javascript:

function checktype() {
if("{!Opportunity.Opportunity_Type__c}" == "X" ||
"{!Opportunity.Opportunity_Type__c}" == "Y" ||
"{!Opportunity.Opportunity_Type__c}" == "Z"
 )
{
alert("Opportunity type: {!Opportunity.Opportunity_Type__c} is not supported ");

return;

}
else
{
window.location.replace("https://Anothersite.COM");
}

}
checktype();
share|improve this question
    
The redirect url contains the opportunity name, i believe that is causing the issue: window.location.replace("anothersite.com/login/…{!Opportunity.Id}&SfdcOpName={!Opportunity.Name}&SfdcServerURL‌​={!API.Partner_Server_URL_280}&SfdcSessionID={!API.Session_ID}"); How do i overcome the double quotes character while dynamically passing the oppty name in the redirect url –  user5352 Aug 13 at 15:14

2 Answers 2

You can use the URLENCODE function on the oppotunity name when generating the url so that it retains all those special characters properly

window.location.replace("anothersite.com/login/…
{!Opportunity.Id}&SfdcOpName={!URLENCODE(Opportunity.Name)}&SfdcServerURL‌​=
{!API.Partner_Server_URL_280}&SfdcSessionID={!API.Session_ID}");

or you can use the javascript encodeURI function as well to get a proper url and redirect

share|improve this answer
    
Thank you.. URLENCODE did the trick.. –  user5352 Aug 13 at 15:30

I hope URLENCODE function will solve your issue. Can you please try replacing SfdcOpName={!Opportunity.Name} with SfdcOpName={!URLENCODE(Opportunity.Name)} and try again. Thanks.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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