1
votes

I want to edit a Sales Order by adding a new Service Item and after adding I need to approve/change the status of SO to "Pending Fulfilment". When saving, the item get added into the sales order, but throws error at the status changing line as "Record has been changed". The script is developed in Suitescript 1.0

Step 1: I load the Sales order and add the service item into it and save the record.

Step 2: Again load the Sales order and set the Sales order status to "Pending Fulfilment" and save the record. Its not saved and ends with "Record has been changed" error.

In step 2, instead of changing sales order status, I tried by changing some other field and this time the SO get saved. So the problem is only with the changing status of SO.

I tried "nlapiSubmitField" api and that also not resolved my problem.

var soRec = nlapiLoadRecord('salesorder', SOId);
....
soRec.selectNewLineItem("item");
soRec.setCurrentLineItemValue("item","item",1093360);
soRec.setCurrentLineItemValue("item","custcol5",ringDesc);
soRec.setCurrentLineItemValue("item","povendor",46063);
soRec.commitLineItem("item");
var order_id = nlapiSubmitRecord(soRec, true, true);

var soObj = nlapiLoadRecord("salesorder", order_id);
soObj.setFieldValue("orderstatus", "B"); // B : Pending Fulfilment
var order_id = nlapiSubmitRecord(soObj, true, true);

The SO contains dropship items, so when saving the SO, the SO should saved and the respective PO should be created.

1
Why do you have to save it before you set orderstatus? Why save the record twice? Also, what script type is this? What entry point? - erictgrubaugh
This is a restlet script. If I save only after setting the "orderstatus", then the "Status" of SO is changed to "Pending Fulfilment", but the PO is not created for the newly added line item. - Ba.Lal
Did you try it without doSourcing and ignoreMandatoryFields defaulted to true? - Coldstar
Yes.. that also not solved the problem - Ba.Lal

1 Answers

0
votes

Actually the problem is, SO gets too much time to save the record (in step 1). Before the save action completed, the record gets again loaded from next step and again tries to save. So I set some setTimeout script to pause the process for a while and continue the sales order load at step 2.