+ Start a Discussion
Joe HayesJoe Hayes 

Invalid or unexpected token on JS button

I have ran the below code through a couple of JS validators and everything seems to be ok. Not sure where I am going wrong with this one. I get an unexpected or invalid token error. It is script for a javascript button on the opportunity page.

var location = "{!Opportunity.Location_for_Training__c}";

if(location.length > 0) {

var opp = new sforce.SObject("Opportunity");
opp.Id = "{!Opportunity.Id}";
opp.InHouseDateRequestChkBox__c = true;

var result = sforce.connection.update([opp]); 
if(result[0].success == 'true') 
alert("Dates requested!");

var t = new sforce.SObject("Task");
var today = new Date();
t.Subject = "In-house Dates Requested";
t.Status = "Completed";
t.OwnerId = "{!User.Id}";
t.ActivityDate = today;
t.WhatId = opp.Id;
t.recordTypeId = "012D0000000YTTW";

opp.InHouseDateRequestChkBox__c = false;

result = sforce.connection.create([t]);
result = sforce.connection.update([opp]);

} else 
   alert("Sending failed");

} else 
   alert("Please add a location for training before requesting dates");