0
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}

/*Getting the Running User Details*/
var result = 
sforce.connection.query(
    "SELECT Advisor__c " + 
    "FROM User " +
    "WHERE Id = '{!$User.Id}'"
);

/*Grab the Records returned by executing the above SOQL Query*/
var userDetails = result.getArray("records")[0];

/*Initializing the Contact record for Update*/
var contactToUpdate = new sforce.SObject("Contact");

contactToUpdate.Id = "{!Contact.Id}";

/*If the Running User is an "Advisor" then set the
Contact With and associated fields*/
if(userDetails.Advisor__c === true){
contactToUpdate.Contact_With__c = "{!$User.Id}";
contactToUpdate.Last_Advisor_Touch__c = new Da​te();
}
/*If the Running User isn't an "Advisor" then set the
Contact With 2 and associated fields*/
else{
contactToUpdate.Contact_With_2__c = "{!$User.Id}";
contactToUpdate.Last_Non_Advisor_Touch__c = new Date();
}

var result = sforce.connection.update([contactToUpdate]);

if(result[0].success === true){
location.reload();
}
else{
alert(result[0].errors.message);
}

I added a custom check box field to our user profiles titled "Advisor" The code is suppose to distinguish which field to update based on if a user has this box checked or not. If yes update this field, If not update that field. Instead though it's returning a 'Unexpected Token ILLEGAL. Not sure why.

Moti Korets
  • 3,738
  • 2
  • 26
  • 35
user3786102
  • 145
  • 6
  • 19

1 Answers1

1

Seems like you have a special hidden character in following line contactToUpdate.Last_Advisor_Touch__c = new Da​ te();

in word Date If you just rewrite it it should work. Specifically you have the infamous ZERO WIDTH SPACE between Da and te probably comes from this. To eliminate such things you can use this tool or this one

Community
  • 1
  • 1
Moti Korets
  • 3,738
  • 2
  • 26
  • 35