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
Ross Gilbert 19Ross Gilbert 19 

Javascript error on custom List Button

{!REQUIRESCRIPT("/xdomain/xdomain.js")} 
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 
{!REQUIRESCRIPT("/support/console/33.0/integration.js")} 

var a = {!LEN( $Setup.New_Opportunity_Settings__c.RecordTypeId__c )}; 

if (a > 0) { 
window.parent.navigateToUrl('/006/e?retURL={!Contact.Id}&RecordType={!$Setup.New_Opportunity_Settings__c.RecordTypeId__c}&{!$Setup.New_Opportunity_Settings__c.ContactFieldNameId__c}={!Contact.Name}&{!$Setup.New_Opportunity_Settings__c.PrimaryContactFieldId__c}={!Contact.Id}&accid={!Account.Id}'); 
} else { 
window.parent.navigateToUrl('/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL={!Contact.Id}&save_new_url=/006/e?retURL={!Contact.Id}&{!$Setup.New_Opportunity_Settings__c.ContactFieldNameId__c}={!Contact.Name}&{!$Setup.New_Opportunity_Settings__c.PrimaryContactFieldId__c}={!Contact.Id}&accid={!Account.Id}'); 
}

This is an onclick javascript button that is on a contact page layout, allowing the user to create a new opportunity.  Seems to work most of the time but occasionally it doesn't, with the error "missing ) after arguments list".  Wondering if anyone knows why this would happen on some contacts not others.
Best Answer chosen by Ross Gilbert 19
JLA.ovhJLA.ovh
Probably not working when your contact name has an ' (single quote) in the name. You should escape it

All Answers

JLA.ovhJLA.ovh
Probably not working when your contact name has an ' (single quote) in the name. You should escape it
This was selected as the best answer
BharathimohanBharathimohan
Hi Ross,

I would recommend to use google chrome developer tools(settings>more tools>developer tools) to see the exact line of error to trace better.
It might be because of any missing value on the current contact in context.


Regards,
Bharathimohan Ramamurthy
Salesforce For All (http://salesforceforall.blogspot.com/)
 
Ross Gilbert 19Ross Gilbert 19
That is it.  Putting jsencode around the contact name appears to resolve this issue with contact name's with an apostrophe in them