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
jingyuan xie 6jingyuan xie 6 

help me out about custom date stamp button

Hi ,I'm trying to create a custom button in leads detail page that when clicked will populate a custom field called attampt date 1 with the current date. The attempt date 1 field is set up as a date field,and JS like this,but when clicked the button,it returned an error message like "A problem with the OnClick JavaScript for this button or link was encountered:expected token="
Can anyone help to find out the reason , thanks!!!

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

var newRecords = []; 

var c = new sforce.SObject("lead"); 
c.id ="{!Lead.Id}"; 
c.{!Lead.attempt1_date__c} = new Date().toISOString(); 
newRecords.push(c); 

result = sforce.connection.update(newRecords); 

window.location.reload();
Best Answer chosen by jingyuan xie 6
VinodKRVinodKR
Hi Jingyuan,

Try This:

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

var c = new sforce.SObject("Lead"); 
c.id ="{!Lead.Id}"; 
c.attempt1_date__c = new Date().toISOString(); 
result = sforce.connection.update([c]); 
window.location.reload();


Thanks,

Let the Force be with you!
Please mark this as best answer if it helps you.

All Answers

jingyuan xie 6jingyuan xie 6
sorry the error message like "A problem with the OnClick JavaScript for this button or link was encountered:UNexpected token="
VinodKRVinodKR
Hi Jingyuan,

Try This:

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

var c = new sforce.SObject("Lead"); 
c.id ="{!Lead.Id}"; 
c.attempt1_date__c = new Date().toISOString(); 
result = sforce.connection.update([c]); 
window.location.reload();


Thanks,

Let the Force be with you!
Please mark this as best answer if it helps you.
This was selected as the best answer
jingyuan xie 6jingyuan xie 6
thanks VKR , this worked! and i aslo tried this one , both are ok? if possible, could you explain the different between the two JS?
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 

var newRecords = []; 

var c = new sforce.SObject("lead"); 
c.id ="{!Lead.Id}"; 
c.attempt1_date__c = new Date(); 
newRecords.push(c); 

result = sforce.connection.update(newRecords); 

window.location.reload();
VinodKRVinodKR
Hi Jingyuan,

The issue in your code was with this,you should have just given object.field.

c.{!Lead.attempt1_date__c} 

Thanks,

Have a good day ahead!
Let the Force be with you!