You are working on your code that simply sets a date field, like this one:
record.setValue({ fieldId : 'trandate', value : '9/10/2018'});

Until you encounter one of the usual NetSuite’s surprises where you get the following error:

“You have entered an Invalid Field Value 8/20/2018 for the following field: trandate”

Invalid Field Value error

Reason 1:

You’re setting a string value.

Unlike SuiteScript 1.0, SuiteScript 2.0 has stricter rules on setting the date and datetime type of fields. For Date type of field, the solution is to use the format.parse method.

var dateValue = format.parse({ value : '9/20/2018', type : format.Type.DATE})

Important Note:

For client-side scripts and user event scripts, format.parse respects the user preferences from Home > Set Preferences.
For scheduled scripts and map/reduce scripts, this method follows the company preferences from Setup > Company > General Preferences.

Reason 2:

The value you’re trying to set does not conform to your date format preferences.

You may have already included the format.parse method but you did not properly follow what’s in your date format preferences.

A good example is when the user preferences show DD/MM/YYYY as the Date Format preference but the value set by the script was: 01/20/2018. This wouldn’t work since the date format must be in Date / Month / Year pattern.

To solve this, you must ensure that the output will be: 20/01/2018.

Did this article help you in some way? I would love to know! Feel free to reach out via the Contact form.

Leave a Reply