Guest User

Untitled

a guest
Oct 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @param {String} type Context Types: scheduled, ondemand, userinterface, aborted, skipped
  3.  * @returns {Void}
  4.  */
  5. function scheduled(type) {
  6.    
  7.     var savedSearchID = 'customsearch_item_fulfilment_test';// ID of the saved search
  8.     var ItemFulfillRec = nlapiLoadSearch('transaction', savedSearchID);
  9.  
  10.     var resultSet = ItemFulfillRec.runSearch();
  11.  
  12.     resultSet.forEachResult(UpdateField);
  13.    
  14.    
  15. // Get the remaining usage points of the scripts
  16. var usage = nlapiGetContext().getRemainingUsage();
  17.  
  18. // If the script's remaining usage points are bellow 1,000 ...      
  19. if (usage < 1000)
  20. {
  21.     // ...yield the script
  22.     var state = nlapiYieldScript();
  23.     // Throw an error or log the yield results
  24.     if (state.status == 'FAILURE')
  25.         throw "Failed to yield script";
  26.     else if (state.status == 'RESUME')
  27.         nlapiLogExecution('DEBUG','Resuming script');
  28. }
  29.    
  30.     function UpdateField(eachResult){
  31.         var id = eachResult.getValue('internalid');
  32.        
  33.         nlapiLogExecution('DEBUG', 'Item Fulfillment ID: ', id);
  34.         var salesOrdId = eachResult.getValue('createdfrom');
  35.    
  36.         var financialLoc = nlapiLookupField('salesorder', salesOrdId, 'custbody_cseg_financialoc');
  37.        
  38.         nlapiSubmitField('itemfulfillment',id, 'custbody_cseg_financialoc', financialLoc);
  39.         return true;
  40.     }
  41.    
  42.    
  43.    
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment