Search code examples
netsuitegettext

Netsuite Invalid API usage. You must use getValue to return the value set with setValue


So I have an odd issue, When I create a new transaction and save, this error in the title gets thrown. But when I edit this transaction after it was created, the getText does not throw this error. Is there something I'm doing wrong or something special needed to getText on a create new record? Here is my code. This is for the afterSubmit method on my User Event Script for Vendor Bill screen. I just noticed getValue does work on create, does not produce this error, just don't understand why? Is this the correct way to get the value on create? To use getValue and getText cannot be used on create? Only for edit?

if (scriptContext.type == scriptContext.UserEventType.CREATE ||
                    scriptContext.type == scriptContext.UserEventType.EDIT) {
        
    // get bill to index
    var Bill = scriptContext.newRecord;
                                
    // fails on this call below on create but works on edit
    var refno = Bill.getText({ fieldId: 'tranid' });

}

Solution

  • This behavior is described in the API documentation here.

    In dynamic mode, you can use getText() without limitation but, in standard mode, limitations exist. In standard mode, you can use this method only in the following cases:

    • You can use getText() on any field where the script has already used setText().
    • If you are loading or copying a record, you can use getText on any field except those where the script has already changed the value by using setValue().

    Apparently the newRecord object falls under the second criteria. At this point, the object only has values set. tranid will have a value with the transaction's internal ID, but it won't have the transaction name stored. To get the text, you will have to use record.load() to get the full record, or use search.lookupFields() to get just the transaction name.