5

I want to get the tranid for an invoice as soon as the invoice has been created.

I have a user event script with the following code.

function showValue()
{
    var tranid = nlapiGetFieldValue('tranid');
    nlapiLogExecution('DEBUG', 'save transaction', nlapiGetRecordType() + ", "+ nlapiGetRecordId() + ", "+ 'tranid' + ": "+ tranid + ", "+ (new Date()))
}

After Submit Function is set to showValue.

The deployment applies to Invoice.

Event Type is set to Create.

When I save a new invoice the following is added to the execution log for the deployment:

"invoice, 1143428, tranid: To Be Generated, Fri Oct 13 2017 04:21:08 GMT-0700 (PDT)"

How can the internal id be set but the tranid still be "To Be Generated"? Surely tranid would be set by the time that the internal id is set.

How can I get the tranid in a user event script?

cja
  • 9,512
  • 21
  • 75
  • 129

2 Answers2

5

I had the same issue before. Straightforward right? I submitted a case for this issue and support told me that the way to do it is to load the record again or do a lookup (Suiteanswer id 34194 and 18215). Which I had before, but I didn't do it because wanted to have an optimized script and just use nlapiGetFieldValue. But at the end of the day, I didn't have a choice.

nlapiLookupField(nlapiGetRecordType, nlapiGetRecordId(), 'tranid')
vVinceth
  • 905
  • 5
  • 7
0

Yeah, silly, but you have to load the record you just 'created' in the DB

For Suitescript 2.0 and 2022 update here is the syntax.

var objRecord = record.load({
        type: record.Type.SALES_ORDER,   //Set your Rec Type
        id: internal_id
        });
        
        var tran_id = objRecord.getValue({ 
        fieldId: 'tran_id'
        });
  • what are you putting for the "internal_id" ? I tried internal_id = scriptContext.newRecord.getValue("internalid") but that didn't work, so I'm a little confused how you are supposed to get the internalID in the record load if you don't know it? – john Jul 26 '23 at 19:32
  • figured it out... var internal_id = scriptContext.newRecord.id; – john Jul 26 '23 at 19:47