简体   繁体   中英

Salesforce JavaScript unterminated string constant Error

I created a button in Salesforce using JavaScript which converts an enquiry (custom object) to a registration (Contact). The button works for myself and any test user I log in as on the same profiles and permissions, however one of my users is report an error when they use the button.

The error is as follows:

'unterminated string constant'

The Code I'm using in the button is as follows:

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

alert('Migration in progress, this page will refresh once it is complete. Please click ok, Please DO NOT press this button again');

if ('{!Enquiry__c.Surname__c}' != ''){
if ('{!Enquiry__c.Client_if_already_on_the_system__c}' == ''){ 

var Reg = new sforce.SObject('Contact'); 

Reg.FirstName = '{!Enquiry__c.First_Name__c}'; 
Reg.LastName = '{!Enquiry__c.Surname__c}'; 
Reg.Gender__c = '{!Enquiry__c.Gender__c}'; 
Reg.MailingStreet = '{!Enquiry__c.Address__c}'; 
Reg.MailingPostalCode = '{!Enquiry__c.Post_Code__c}'; 
Reg.MailingCity = '{!Enquiry__c.City_Town__c}'; 
Reg.MailingState = '{!Enquiry__c.County__c}'; 
Reg.HomePhone = '{!Enquiry__c.Home_Number__c}'; 
Reg.MobilePhone = '{!Enquiry__c.Mobile_Number__c}'; 
Reg.Email = '{!Enquiry__c.E_mail__c}'; 
Reg.Lastest_Enquiry__c = '{!Enquiry__c.Id}'; 

result = sforce.connection.create([Reg]); 

if (result[0].success == 'true'){ 
alert('A new Registration with the name - ' + Reg.FirstName + ' ' + Reg.LastName + ' was successfully created, Please DO NOT press this button again as duplication\'s will be created, Your client will be automatically connected to this enquiry'); 
javascript: document.location.reload(true); 
} 
}else{ 
alert('Cannot Migrate to Registration as there is already a Client connected to this Enquiry'); 
}
}else{
alert('Cannot Migrate to Registration as Surname is blank!'); 
}

The user has told me they are using IE as a browser, I've tested the button on Chrome, Edge and the most up to date IE. Anyone have any ideas of whats wrong?

what is the type for Reg.FirstName and LastName? Are you using textarea type for these two fields? Because if user enter any of the name with a carriage return \\r or \\n alert will fail with the same error and it will be a random based on the input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM