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
Jay REIJay REI 

How to set Date Field to Null?


Hi
 
I am using AJAX ToolKit version 3.
 
I want to know how to set a date field in a DynaBean to null and save it(update)?
 
var tmpDOB=new Date("00/00/0000");
tmpDOB=null;
MyBean.set("DateOfBirth__c",tmpDOB);
 
saveResultCreate = sforceClient.Update(MyBean);
 
The above code runs with no error, but the date field is not set to null and old value of the field is retained.
 
Thanks
Jay
 
Ron HessRon Hess

use the fieldsToNull array on the dynabean

example from an unrelated scontrol, where bean is a dynabean and i am clearing out a number field, same should work for date fields

Code:

} else { // must null it out
 bean.fieldsToNull.push('Sales_Discount__c');
}
 


 

 

Jay REIJay REI
sample working code
 
Hi,
Thanks, it worked.
The following is the working code.
=============================
var WenBean = new Sforce.Dynabean("Wen_s_test__c");         
WenBean.set("Id",document.all("hdnId"+RowId).value);
WenBean.set("Name",document.all("txtName" + RowId).value);
WenBean.set("Address__c",document.all("txtAddress" + RowId).value);
WenBean.set("Phone__c",document.all("Phone" + RowId).value);

if(document.all("txtDOB" + RowId).value!="")
{
     var tmpDOB=new Date(document.all("txtDOB" + RowId).value);
     WenBean.set("DateOfBirth__c",tmpDOB);
}
else
{
     WenBean.fieldsToNull.push("DateOfBirth__c");
}    

saveResultCreate = sforceClient.Update(WenBean);