Wednesday, May 29, 2019

Close Sales Order via SuiteScript

Each line item has an 'isclosed' column which pertains to the 'Closed' checkbox in each line item. When all of the line items are closed, the order is automatically closed. Users could close the line items either through the UI or through scripts. Below is a sample scheduled script to close all lines in a given Sales Order, closing the said order:

    var so_rec = nlapiLoadRecord('salesorder', id);  //id is internal id of Sales Order to close
    for(var i = 1; i<=so_rec.getLineItemCount('item'); i++) {  //loop through the all the lines of the order
       so_rec.setLineItemValue('item', 'isclosed', i, 'T');  // check the 'Closed' column
    nlapiSubmitRecord(so_rec);  // submit the record


  1. Thank you so much, in suitecript 2.0 is
    for (var i = 0; i < SaleOrder.getLineCount({sublistId: 'item'}); i++) {

    sublistId: 'item',
    fieldId: 'isclosed',
    line: i,
    value: true

    }{ ignoreMandatoryFields: true });

  2. Thank you. Working on an integration system and the NetSuite docs certainly didn't make this very obvious.

  3. How we can close the sales order having item Groups by scripting.