In the button code, the line

dog.colMrk__c = "{!Birth_Record__c.Characteristics__c}";

causes an error "Unexpected token ILLEGAL" when there are separate lines in the Characteristics field. Is there a way around this? Both fields are Long Text Area.


var pupIn = "{!Birth_Record__c.dog_Name2__c}"; 

if (pupIn != "") { 
alert("A dog record has already been created for this birth record. Please click the link next to Puppy Name to view that record.") 
var dog = new sforce.SObject("Dog__c"); 

dog.Name = "{!Birth_Record__c.Name}"; 
dog.sex__c = "{!Birth_Record__c.Gender__c}"; 
dog.Dame__c = "{!Birth_Record__c.Dame_ID__c}"; 
dog.Sire__c = "{!Birth_Record__c.Sire_ID__c}"; 

dog.colMrk__c = "{!Birth_Record__c.Characteristics__c}";

dog.Breed__c = "{!Birth_Record__c.Breed__c}"; 

var by = "{!YEAR( DATEVALUE(Birth_Record__c.Birth__c) )}"; 
var bm = "{!MONTH( DATEVALUE(Birth_Record__c.Birth__c) )}"; 
if (bm.length == 1){ 
bm = "0"+bm; 
var bd = "{!DAY( DATEVALUE(Birth_Record__c.Birth__c) )}"; 
if (bd.length == 1){ 
bd = "0"+bd; 
var b = by+"-"+bm+"-"+bd; 
dog.birthdate__c = b; 

var result = sforce.connection.create([dog]); 

var nextPg = result[0].id; 
var newRecords = []; 
var c = new sforce.SObject("Birth_Record__c"); 
c.id ="{!Birth_Record__c.Id}"; 
c.dog_Name2__c = result[0].id; 
result = sforce.connection.update(newRecords); 
window.location = "/" + nextPg; 
alert('Could not create record '+result); 

That's because you cannot have multiline strings in Javascript unless they are properly escaped.

Try JSENCODE on the string: dog.colMrk__c = "{! JSENCODE(Birth_Record__c.Characteristics__c) }";

JSENCODE documentation can be found here.

  • Thank you for the code, the link and the quick response! – Jennifer Oct 12 '15 at 17:39

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.