When an item on a sales order is a Special Order Item, a PO is automatically created when the Sales Order is created. But if that purchase order gets deleted, is there any way to re-submit the sales order to have it be re-created? Obviously a user could click the "Spec. Ord" link on the sales order line, but is that the only way? I was hoping that simply re-submitting the sales order would cause any special order POs to be recreated, but it doesn't. I've tried digging through fields in the back end of the SO/line item, but I can't find anything that will trigger this to happen.
The reason I'm asking is that I'm trying to write a script that will delete a PO/WO and then recreate it from the sales order. But the 2nd part doesn't seem to be possible. Here's what I have:
recreateMarkedOrders = function(recType, recId) { var createdFrom, filters, i, orderFields, orderType, result, results, sourceRec, toDelete; orderFields = nlapiLookupField(recType, recId, ['createdfrom', 'custbody_recreaterecord']); createdFrom = orderFields['createdfrom']; toDelete = orderFields['custbody_recreaterecord']; if (toDelete !== "T") { return; } // Step 1: Find any child records to delete filters = [['createdfrom', 'anyof', recId], 'and', ['mainline', 'is', 'T']]; results = nlapiSearchRecord('transaction', null, filters) || []; for (i = 0, i < results.length; i++) { result = results[i]; nlapiDeleteRecord(result.getRecordType(), result.getId()); nlapiLogExecution("debug", "Child Record Deleted", (result.getRecordType()) + " " + (result.getId())); } // Step 2: Delete parent record nlapiDeleteRecord(recType, recId); nlapiLogExecution("debug", "Parent Record Deleted", recType + " " + recId); // Step 3: Recreate SO to trigger PO/WO recreation (doesn't work) if (createdFrom) { orderType = nlapiLookupField('transaction', createdFrom, 'recordtype'); sourceRec = nlapiLoadRecord(orderType, createdFrom); nlapiSubmitRecord(sourceRec, true, true); } return nlapiLogExecution("debug", "Execution Complete", "Resubmitted " + orderType + " " + createdFrom); };