This topic contains 7 replies, has 0 voices, and was last updated by chanarbon 8 years ago.

  • Author
    Posts
  • #1731

    mvk4a092

    How to get Current Record type and internal id dynamically in UserEvent AfterSubmit in SuiteScript 2.0 ? In SuiteScript 1.0 nlapiGetRecordType() and nlapiGetRecordId() what in SuiteScript 2.0 will replace those two apis?

    Please Help!
    This is a cached copy. Click here to see the original post.

  • #1732

    david.smith

    scriptContext.currentRecord.type and scriptContext.currentRecord.id

  • #1733

    JacksonP

    They also added a currentRecord module!

    https://system.netsuite.com/app/help…625600928.html

  • #1734

    Olivier Gagnon NC

    Note that currentRecord on aftersubmit is buggy and does not return correct values. You must load the record just saved as a workaround.

  • #1735

    mvk4a092

    My Code is

    /**

    *@NApiVersion 2.x

    *@NScriptType UserEventScript

    */

    define([‘N/record’],

    function(record,currentRecord) {

    function afterSubmit(scriptContext) {

    log.debug(‘script Triggered’,’User Event’);

    var recordId=scriptContext.currentRecord.id;

    log.debug(‘recordId’,recordId);

    var objRecord = record.load({type: record.Type.SALES_ORDER,id: recordId,isDynamic: true,});

    log.debug(‘objRecord’,objRecord);

    }

    return {

    afterSubmit: afterSubmit

    };

    });

    Error is: org.mozilla.javascript.EcmaError: TypeError: Cannot read property “id” from undefined (/SuiteScripts/User Event 2.0.js#9)

    โ€‹Help Me….

  • #1736

    JacksonP

    I noticed that you’re not loading the ‘N/currentRecord’ module in the define statement, but passing a variable for currentRecord.

  • #1737

    Olivier Gagnon NC

    See corrections below. Give this a shot.

    /**

    *@NApiVersion 2.x

    *@NScriptType UserEventScript

    */

    define([‘N/record’],

    function(record) {

    function afterSubmit(scriptContext) {

    log.debug({title:’script Triggered’,details:’User Event’});

    var recordId=scriptContext.newRecord.id;

    log.debug({title:’recordId’,details:recordId});

    var objRecord = record.load({type: record.Type.SALES_ORDER,id: recordId,isDynamic: true,});

    log.debug({title:’objRecord’,details: objRecord});

    }

    return {

    afterSubmit: afterSubmit

    };

    });

  • #1738

    chanarbon

    Hi @mvk4a092,

    Please note that for the afterSubmit entry point, it does not have a context.currentRecord. User Event Scripts contain context.oldRecord and context.newRecord except beforeLoad which only has context.newRecord that’s why you should use context.newRecord for this concern.

You must be logged in to reply to this topic.