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 

Set Date Field to Null using AJAX Toolkit

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(WenBean);
 
The above code runs with no error, but the date field is not set to null.
 
Thanks
Jay
 
Jay REIJay REI

Hi

Please ignore the typo in the question above.

saveResultCreate = sforceClient.Update(MyBean);

Thanks

Jay

 

SteveBowerSteveBower

Use the fieldsToNull array in the object instead of trying to .set(field,null) which doesn't work.

Search the boards for sample code.

Jay REIJay REI

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);