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
Del_SantosDel_Santos 

Updating a Date/Time field

Hi,

 

I am new to Salesforce programming. Please help me with my problem.

 

I have a code that update the value of Email_Sent__c after clicking a custom button.

=================================================================

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
var camp= new sforce.SObject("Campaign");
camp.id= "{!Campaign.Id}";
camp.Email_Sent__c ="true";
try {
resultGo = sforce.connection.update([camp]);
if(!resultGo[0].getBoolean("success"))
{
window.alert(resultGo[0]);
}
window.location.href = window.location.href;
} catch (e)
{
window.alert(e);
}

 

 

My problem is, I created a new field Email_Sent_Date__c in a Date/Time type,  I want also this button to supply the current date and time once clicked. I did below code but returned me an error.

===========================================

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
var camp= new sforce.SObject("Campaign");
camp.id= "{!Campaign.Id}";
camp.Email_Sent__c ="true";

camp.Email_Sent_Date__c=sysdate();
try {
resultGo = sforce.connection.update([camp]);
if(!resultGo[0].getBoolean("success"))
{
window.alert(resultGo[0]);
}
window.location.href = window.location.href;
} catch (e)
{
window.alert(e);
}

 

 

 

 

Thanks in advance.

Del

Best Answer chosen by Admin (Salesforce Developers) 
vanessenvanessen

This is javascript ,sysdate (if i am not wrong , does not exist in javascript), try :

var now = new Date();

camp.Email_Sent_Date__c = now and see if the error continues.