Monday, June 24, 2019

Set a Field value for a Date/Time Field via Script

When setting a custom field of type : Date/Field use 'datetimetz' as the format since if you use 'datetime' as format it will throw an Invalid Field Value error. Please refer to the sample below which creates a new custom record and sets the field value for custom field of type : Date/Time  :

var date = new Date();
var rec = nlapiCreateRecord('customrecord_ct_hr_translation');  //Type of the new record being created, if setting value on an existing record Load the record instead of creating one  


var date1 = nlapiDateToString(date,'datetimetz');
rec.setFieldValue('name','xxx');  //Set the Name of the record
rec.setFieldValue('xxx',date1);   // Internal id of the custom field of type : Date/Time  
nlapiSubmitRecord(rec,true);

 

No comments:

Post a Comment