This topic contains 4 replies, has 0 voices, and was last updated by TheUsualSuspect 7 years, 3 months ago.

  • Author
    Posts
  • #18345

    NateS

    I’m creating a script that sends an email after an item fulfillment has been marked as shipped.

    Here is a small sample of my script. It’s all ready to go except I’m not sure how to dynamically grab the record ID of the item fulfillment that was just marked shipped. Is there a way to use scriptContext to store the item fulfillment id as the parameter to the afterSubmit function?

    Code:
    define([‘N/email’, ‘N/record’],function(email, record) {
    function afterSubmit(scriptContext) {

    var fromId = 450103; // my internal ID
    var itemFulfillmentId = ”; //THIS IS THE RECORD ID I NEED TO GRAB

    //loads item fulfillment
    var itemFulfillment = record.load({
    type: record.Type.ITEM_FULFILLMENT,
    id: itemFulfillmentId,
    isDynamic: true
    });
    This is a cached copy. Click here to see the original post.

  • #18346

    erictgrubaugh

    Code:
    scriptContext.newRecord.id


    NateS replied on 07/27/2017, 12:33 PM: Thank you very much.

  • #18347

    AE Cloud Consultants

    Hello Nates.

    I dont think you are doing it right. This is how I recommend you do it

    Deploy your script as a user event script After Submit

    A user event script is deployed on the record, so you can always use “scriptContext.newRecord” to get record. You just need to check the IF status if =Shipped, then send the email. No need to load the record, just send the email, and link it to the transaction.

  • #18348

    a.rivetti@clustin.com

    New Record is not always availble. If you are keeping synced other record related to the record in which UE is acting, you have also to consider the delete event management which is not triggering the aftersubmit record. In this case, you have to manage it in a before Submit event and use OLD record for get values.

    For other users: what about the nlapiGetRecordId() ? In 2.0 which is the equivalent API?

  • #18349

    TheUsualSuspect

    You can log the object just like any other object in JavaScript. I don’t know why the context objects aren’t very well documented. I usually check the keys to see what I can use while scripting.

    beforeLoad: function(context){

    log.debug({title:context, details: Object.keys(context)});

    log.debug({title:context, details: JSON.stringify(context)});

    },

You must be logged in to reply to this topic.