Error: “Invalid API usage. You must use getValue to return the value set with setValue”
The above error message is specific to SuiteScript, and it usually occurs when we’re trying to use getText() on a field that only supports getValue() — such as internal ID fields or hidden/system fields that aren’t rendered as dropdowns or select fields in the UI.
let acntId = newRecord.getValue({ fieldId: 'account' });
let acntName = newRecord.getText({ fieldId: 'account' }); // Throws error
This fails because the account field in the record is not a standard select field in the UI, or it’s a backend-only field. In these cases, NetSuite expects us to retrieve the internal ID using getValue() — and does not allow getText() usage.
Solution: Use search.lookupFields
Instead of using getText(), use search.lookupFields() to retrieve the readable name from the Account record, like this:
const search = require('N/search');
let acntId = newRecord.getValue({ fieldId: 'account' });
let accountText = '';
if (acntId) {
let result = search.lookupFields({
type: 'account',
id: acntId,
columns: ['name']
});
accountText = result.name || '';
}
NOTE:
- This is a very common scenario when working with non-UI fields, especially account, entity, department, etc., on transactions and sublists.