3
votes

I am trying to close a Sales Order using Suite Script in NetSuite.

I noticed that records which are already closed have their 'status' set to 'Closed'. I tried setting this field before submitting the record but this doesn't work and the record still remains in the 'Pending Fulfilment' stage.

Are there any other fields involved?

Thanks in advance!

5

5 Answers

9
votes

No actual 'Close' equivalent status for transaction record.

You have to iterate over all line items and set to close, then resubmit the record to commit the changes.

Here is a sample code:

var obj = nlapiLoadRecord('salesorder', 1);
var count = obj.getLineItemCount('item');

for(var i = 1; i <= count; i++)    {

    obj.setLineItemValue('item', 'isclosed', i, 'T');

}

nlapiSubmitRecord(obj);
3
votes

Try with the below code using aftersubmit() in suitescript 2.0. It will set the field "isclosed" to 'true'.

  var itemcounts = salesorderRecord.getLineCount({
                    sublistId: 'item'
                });
                for (var i = 0; i < itemcounts; i++) {
                    var lineNum = salesorderRecord.selectLine({
                        sublistId: 'item',
                        line: i
                    });
                    var setclosed = salesorderRecord.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'isclosed',
                        line: i,
                        value: true,
                        ignoreFieldChange: true
                    });
                    salesorderRecord.commitLine({
                        sublistId: 'item',
                        line: i
                    });

                }salesorderRecord.save();
1
votes
  var count = poRec.getLineCount({
                sublistId: 'item'
            });

            for (var i = 0; i < count; i++) {

                poRec.setSublistValue({
                    sublistId: 'item',
                    fieldId: 'isclosed',
                    line: i,
                    value: true
                });

            }

suitescript 2.0 code snippet

0
votes

I was able to close the Sales Order by closing individual line items the order contains.

There is a line item field 'isclosed' that needs to be set to true('T') for each line item.

0
votes
nlapiVoidTransaction('salesorder', id)