Skip to content

Instantly share code, notes, and snippets.

@cafeasp
Created July 19, 2019 22:21
Show Gist options
  • Save cafeasp/fdd8b777dff43009d2047c04a6815f1e to your computer and use it in GitHub Desktop.
Save cafeasp/fdd8b777dff43009d2047c04a6815f1e to your computer and use it in GitHub Desktop.
Sales Order - Close Sales Order
function closeSalesOrder(salesOrderInternalId) {
try {
var order = record.load({
id: salesOrderInternalId,
type: record.Type.SALES_ORDER,
isDynamic: true
});
var itemIndex = 0;
var itemCount = order.getLineCount({
"sublistId": "item"
});
log.debug('item count', itemCount);
while (itemIndex < itemCount) {
order.selectLine({
"sublistId": "item",
"line": itemIndex
});
order.setCurrentSublistValue({
"sublistId": "item",
"fieldId": "isclosed",
"value": true
});
order.commitLine({
"sublistId": "item"
});
itemIndex++;
}
var recordId = order.save({
enableSourcing: false,
ignoreMandatoryFields: false
});
return true;
}
catch (error) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment