Thursday, September 20, 2018

Check quantity availability of an item changed on the fly, and find the Purchase Orders associated to that item

How to check if the quantity available of an item is changed on the fly and find any Purchase Orders associated to that item.
 
Say, if the number of item on hand was reduced to zero, the Purchase Orders that contains the item must be retrieved.
 
1. Create an After Submit User Event script deployed to an Item Fulfillment Record with this script:
 
//This function iterates through all of the items being fulfilled.

function getItemID()
{
 var itemCount = nlapiGetLineItemCount('item');
 for (i=1;i<=itemCount;i++)
 {
  var qtyAvail = nlapiLookupField('item',nlapiGetLineItemValue('item','item',i),'quantityavailable');
  var itemID = nlapiGetLineItemValue('item','item',i);
  nlapiLogExecution('Debug',nlapiGetLineItemValue('item','item',i),nlapiGetLineItemText('item','item',i));
  nlapiLogExecution('Debug',nlapiGetLineItemText('item','item',i),qtyAvail);
  if (qtyAvail == 0) {
   searchPO(itemID);
  }
 }
}

//this function search for POs containing the item whose quantity on hand is reduced to zero.

function searchPO(itemID)
{  
 var filters = new Array();
 filters[0] = new nlobjSearchFilter( 'item', null, 'is', itemID,null); 
 var searchResult = nlapiSearchRecord('purchaseorder',null,filters,null);
 
 if (searchResult.length > 0)
 {
  for (i = 0; i < searchResult.length;i++)
  {
   nlapiLogExecution('Debug','PO Result',searchResult[i].getId());
  }
 }
}  

No comments:

Post a Comment