0

I'm trying to update Term field on Sales Order Item Line in NetSuite. I can do that fine using ue (user event script) on beforeSubmit event. That works when I hit Save button when Sales Order is in Edit mode. Now, the issue: I am trying to update Sales Order Item field (Term) BEFORE Save button is hit but AFTER Add button is clicked, for components of Item Group.

I have written a function and added to postSourcing(scriptContaxt) event that does the updating but it works only for NON-Inventory Items. This does not work for Item Groups. When Item Group is added to the Sales Order, inventory (components) are automatically populated onto the form.
Does anybody know what event is triggered when components of Item Group are added to the Sales Order form?

Thank you Kris

OK... Further research and explanation: This is the code for updating a single filed when Non-Inventory Item is added to the Sales Order (adding SKU number to the Sales Order Line):

function postSourcing(scriptContext) 
{
    setSalesOrderItemTerm(scriptContext.currentRecord);
}

function setSalesOrderItemTerm(salesorder)
{   
    var itemId = salesorder.getCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'item'
    });

    if(!itemId)
        return;

    var result = search.create({
        type: search.Type.ITEM,
        columns: ['custitem_abs_item_term'],
        filters: [{name: 'internalid',operator: search.Operator.IS,values: itemId},
                  {name: 'isinactive',operator: search.Operator.IS,values: 'F'}]
        }).run().getRange({start: 0, end: 1});

    if(result.length > 0)
    {
        var term = result[0].getValue('custitem_abs_item_term');

        salesorder.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'custcol_swe_contract_item_term_months',
            value: term
        });
    }
}

This works absolutely fine for a single, Non-Inventory Item. On the other hand when I try to add Item Group (this is different than KIT) the Term field (id: custcol_swe_contract_item_term_months) is not being updated from its item, the Term field is updated with value on the Item Group. FYI. Item Group is constructed with Item Group (Group Header called Group), its components (other Item types i.e. Non-Inventory Items) and Empty Items (called End Group -> usually empty)

So when you have an Item Group that has two Non-Inventory Items in it and you try to add that Item Group to Sales Order those two Non-Inventory items will be automatically added to Sales Order (along with Group and End Group row). I am trying to find out on what event those two Non-Inventory items are added to Sales Order.

I hope this is more clear now. Thank you Kris

kriss2
  • 33
  • 2
  • 9

1 Answers1

0

My answer below, also applies to this

https://stackoverflow.com/a/44013939/5389329 "Creating a SalesOrder within NetSuite with Item Groups"

Community
  • 1
  • 1
Darren Hill
  • 27
  • 2
  • 6
  • First of, thank you Darren for looking into this, much appreciated it. I think we will try to move the whole functionality to the server side and try to get item term (whether it is Non-Inventory Item or Item Group) in an afterSubmit function of the user event. I think in afterSubmit all the values (including ids of the Item Group components) should be in DB? please, correct me If I am wrong. (btw. I was not aware that Item Group is only Client Side functionality). – kriss2 May 24 '17 at 21:03