I am looping through a sales order and marking eac...
# suitescript
s
I am looping through a sales order and marking each line as closed. Then at the end I am doing salesOrder.save(). However, I am receiving a "RCRD_HAS_BEEN_CHANGED". Any Thoughts?
Copy code
// load and return the sales order for updating
var so = loadSO(uniqueId);
// delete/archive only  for A(Pending Approval) or B(Pending Fulfillment) from restlet
var orderStatus = so.getValue("orderstatus").formatValue();
if (orderStatus === "A")
{
	var sublistCount = so.getLineCount({
		sublistId: "item"
	});
	for(var i = 0; i < sublistCount; i++)
	{
		so.selectLine({
			sublistId:"item",
			line:i
		});
		so.setCurrentSublistValue({
			sublistId: "item",
			fieldId: "isclosed",
			value: true
		});
		so.commitLine({sublistId:"item"});
	}
	so.save();
}
p
What context are you doing this in? What script type & which function (before submit/after submit etc).
s
It's in a restlet and using record.load()
s
Is there a particular reason you are loading it in dynamic mode? I would try not using dynamic mode.
s
It's been so long, but do you have to have dynamic mode to do select line and commit line?
s
yes, if you are not loading the record in dynamic mode then you just use setSublistValue()
s
that is a shared method, and the other method's require isDynamic
why would that cause it to throw that specific error?
s
I'm not sure but taht could definitely be the problem
s
weird. ok thanks!
b
that code by itself doesnt look like it should cause that error
usually caused by something else loading and saving the record before your code finishes
s
Yeah, that's what I was originally thinking
b
i doubt that the code you shared is all thats going on, simply because there is a weird formatValue method in it
but dynamic mode is perfectly capable of closing sales order lines
s
all that does is makes sure it trims and capitzlies the a