4

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!

Faraz
  • 57
  • 1
  • 5

5 Answers5

10

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);
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
eliseobeltran
  • 568
  • 3
  • 11
4

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();
2
  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

marg
  • 91
  • 1
  • 12
0

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.

Faraz
  • 57
  • 1
  • 5
0
nlapiVoidTransaction('salesorder', id)
Remees M Syde
  • 2,564
  • 1
  • 19
  • 42
  • 3
    Welcome to Stack Overflow! Please edit with more information. Code-only and "try this" answers are [discouraged](http://meta.stackexchange.com/questions/196187/is-try-this-bad-practice), because they contain no searchable content, and don't explain why someone should "try this". – Rick Smith Sep 09 '15 at 20:55