When creating a new record and testing a script, you may encounter the following error:
INVALID_API_USAGE – Invalid API usage. You must use
getSublistValueto return the value set withsetSublistValue.
This error typically occurs when using getSublistText() in situations where NetSuite expects getSublistValue().
Solution: Switch to getSublistValue
One effective fix is to replace getSublistText() with getSublistValue(). Doing so resolves the error and ensures proper handling of sublist values.
Alternative Approach
NetSuite has recently introduced changes that affect the use of getText and getSublistText. If you attempt to use these functions without corresponding setText or setSublistText, errors may occur.
An alternative solution is to use the AfterSubmit event:
- Load the record in
afterSubmit. - Use
getTextorgetSublistTextsafely. - Save the record after modifications.
Key Takeaways
- Use
getSublistValuewhen retrieving values set withsetSublistValue. - Avoid using
getSublistTextunless paired withsetSublistText. - Consider the AfterSubmit approach if you need to work with text values.