Don’t Miss it: Top Strategies for Driving Diversity

days / hours / minutes / seconds

Register Here »
NetSuite logo
workplace by meta logo
University icon
Atlassian Logo
Adoption blog
November 16, 2023
2 min
reading time

SuiteScript 2.0: The Simple Solution For Solving The ‘Invalid Field Value’ Error for Date Type of Field

Share this article
/*SoMe buttons*/ <-- Facebook Share Button Code --> <-- Facebook Share Button Code --> <-- Twitter Share Button Code --> <-- Twitter Share Button Code --> <-- Linkedin Share Button Code --> <-- Linkedin Share Button Code -->

When working with code, it's almost certain you will come across an error message in your day-to-day work. But just receiving an error message isn’t necessarily a cause for panic. A common error seen in SuiteScript 2.0 is a date type of field error

To give you an example of this error, say you are working on code that simply sets a date field, like this one:

record.setValue({ fieldId : 'trandate', value : '9/20/2018'});

At a glance, everything looks fine, until you encounter one of NetSuite’s surprise error messages like below:


"You have entered an Invalid Field Value 
9/20/2018 for the following field: 

So why is this happening? There are two main reasons. We’ve broken them down for you below.

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 as shown below:

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

Important Note

For client-side 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 Set Value Doesn’t Conform to Your Date Format Preferences

This could be the source of your troubles even if you may have already included the format.parse method, but you didn’t 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: 09/20/2018 (e.g., MM/DD/YYYY). This wouldn’t work since the date format must be in the correct order..

To solve this, you must ensure that the output shows 20/09/2018.

Get More NetSuite Advice from ServiceRocket

With ServiceRocket, you’ll get certainty, expertise and success built into your NetSuite implementation, configuration and custom development. When you work with us, you get access to NetSuite-trained Certified Developers with over 400+ NetSuite scripts and 50+ Suitelet workflows combined. Rest assured that ServiceRocket will help you find success and provide you with the opportunities you need to transform your business.

Do you have NetSuite license management, implementation, administration, support or custom development needs? We’ve got your back! Contact our NetSuite Certified Experts today.

Ensure the highest return on your NetSuite investment with our custom development or administrative services.

Learn MoreServiceRocket Backed - We've got your back badge