Trying to get the record id for an after submit on...
# suitescript
c
Trying to get the record id for an after submit on invoice SA: 34194 says it should just be record.id but when I log it it doesn’t give me anything
b
Probably want to share your code
c
@battk
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/record'],
/**
 * @param {record} record
 */
function(record) {

    function afterSubmit(scriptContext) {
    	
    	var recID = record.id;
    	var fieldLookUp = search.lookupFields({
    	type: search.Type.PURCHASE_ORDER, // enum of the record created or where the script will be deployed
    	id: recID,
    	columns: ['tranid']
    	});
    	log.debug('id', fieldLookUp);

    }

    return {
        afterSubmit: afterSubmit
    };
    
});
Thats what the SA (https://netsuite.custhelp.com/app/answers/detail/a_id/71079/kw/34194/related/1) has, I changed the type to enum to INVOICE, but when I do a log for recID it comes up empty, so this code is giving me an error
Copy code
{
   type: "error.SuiteScriptError",
   name: "SSS_MISSING_REQD_ARGUMENT",
   message: "search.lookupFields: Missing a required argument: id",
   stack: [
      "createError(N/error)",
      "afterSubmit(/SuiteScripts/SUE_InvoiceClassifications.js:26)",
      "createError(N/error)"
   ],
   cause: {
      name: "SSS_MISSING_REQD_ARGUMENT",
      message: "search.lookupFields: Missing a required argument: id"
   },
   id: "",
   notifyOff: false,
   userFacing: true
}
s
scriptContext.newRecord.id...
record
is the suitescript module for doign things with records, record.id makes no sense in this scenario
b
Low quality sa article, code is wrong
c
@Sandii are you saying it should be
var recID = scriptContext.record.id;
? I tried that and it still says "id" is undefined.
s
scriptContext.newRecord.id
would be my guess, scriptContext.record is not a thing
c
@battk what am I missing here? I just want to get the id of the invoice that was just created
s
You should get familiar with traversing the help pages... afterSubmit(scriptContext) This page shows you what is on the scriptContext
c
I got it
var invoiceRec = context.newRecord; var recID = invoiceRec.id;
seems to work
👍 1