ANS-1284 · SUITESCRIPT DEVELOPMENT
How to Correctly Compare Datetime Field Values in NetSuite 2.0
Understand the difference in how NetSuite 2.0 handles datetime field values compared to NetSuite 1.0 to ensure accurate comparisons in scripts.
Short answer
In NetSuite 2.0, comparing datetime field values directly using `getValue()` will always return false because it retrieves an object. To perform accurate comparisons, use `getText()` instead. This method returns the string representation of the datetime field's value, allowing for proper string-based comparisons in your scripts.
Scenario
When attempting to compare datetime field values in NetSuite 2.0 scripts, developers may encounter situations where comparisons using the `getValue()` method consistently return false. This occurs because, unlike NetSuite 1.0's `nlapiGetFieldValue`, the `getValue()` method in NetSuite 2.0 retrieves the datetime field's value as an object rather than its string representation.
Solution
In NetSuite 1.0, retrieving a datetime field's value using nlapiGetFieldValue would return its string representation. In NetSuite 2.0, however, the getValue() method returns an object. Directly comparing two such objects with != will always result in false. The solution is to use getText(), which returns the text that appears in the datetime field, enabling proper string comparisons.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
