RCRD_LOCKED_BY_WF: This record has been locked by a user defined workflow.
To get around the error, control Lock Record actions by providing more flexible conditions. One solution is to create a custom transaction body field, which will store the User's ID who needs to update the record.
Custom Field then should be added on the Workflow Condition so it may know if record should be locked or not.
On the script, update the custom transaction body field value with the User's ID before editing. For this article, the field's name is 'PO Lock Exception' (Script ID: custbody_po_lock_exception).
var poId = '12345';
// Update transaction's PO Lock Exception field:nlapiSubmitField('purchaseorder', poId, 'custbody_po_lock_exception', nlapiGetUser());
/* Record is no longer locked at this point.
* Normally, without the workaround, nlapiLoadRecord would fail.
*/
var po = nlapiLoadRecord('purchaseorder', poId);
po.setFieldValue('department', '2');
po.setFieldValue('location', '3');
po.selectNewLineItem('item');
po.setCurrentLineItemValue('item', 'item', 250);
po.setCurrentLineItemValue('item', 'quantity', 2);
po.commitLineItem('item');
nlapiSubmitRecord(po);
// Update transaction again to empty out the 'PO Lock Exception' and lock again
nlapiSubmitField('purchaseorder', poId, 'custbody_po_lock_exception', '');
Technically, nlapiSubmitField also works even if the record is locked. However, it is only applicable for inline editable fields (See Inline Editing Using nlapiSubmitField Help Guide documentation) and main body fields. The API cannot be used to update sublists and fields that are not inline editable.
No comments:
Post a Comment