Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {String} type Context Types: scheduled, ondemand, userinterface, aborted, skipped
- * @returns {Void}
- */
- function scheduled(type) {
- var savedSearchID = 'customsearch_item_fulfilment_test';// ID of the saved search
- var ItemFulfillRec = nlapiLoadSearch('transaction', savedSearchID);
- var resultSet = ItemFulfillRec.runSearch();
- resultSet.forEachResult(UpdateField);
- // Get the remaining usage points of the scripts
- var usage = nlapiGetContext().getRemainingUsage();
- // If the script's remaining usage points are bellow 1,000 ...
- if (usage < 1000)
- {
- // ...yield the script
- var state = nlapiYieldScript();
- // Throw an error or log the yield results
- if (state.status == 'FAILURE')
- throw "Failed to yield script";
- else if (state.status == 'RESUME')
- nlapiLogExecution('DEBUG','Resuming script');
- }
- function UpdateField(eachResult){
- var id = eachResult.getValue('internalid');
- nlapiLogExecution('DEBUG', 'Item Fulfillment ID: ', id);
- var salesOrdId = eachResult.getValue('createdfrom');
- var financialLoc = nlapiLookupField('salesorder', salesOrdId, 'custbody_cseg_financialoc');
- nlapiSubmitField('itemfulfillment',id, 'custbody_cseg_financialoc', financialLoc);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment