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:
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