Tuesday, September 25, 2018

Get the value of a date field and add days to it and then set it to a date field in Netsuite regardless of the date format set under Set Preferences

Note: Thisrequires SuiteScript knowledge.

 

Beforeyou can use nlapiAddDays on a date field, the value of the date field must beconverted into a date object using nlapiStringToDate. Then usenlapiDateToString to convert the date back to a string in the date format ofthe current user. Otherwise, the value being set will be a date data type (nota string), so NaN (not a number) will be set on the date field.

 

Seesample code below:

 
EstCloseDate = nlapiStringToDate(nlapiGetFieldValue('expectedclosedate'));
NewDueDate = nlapiDateToString(nlapiAddDays(EstCloseDate,60));
nlapiSetFieldValue( 'duedate', NewDueDate);

No comments:

Post a Comment