Hi, can anyone pls assist with correcting this script I have used from NS site?
It changes the cost direct from a PO back to the item record & only changes the inventory item and not the assy items?
Check
var item = nlapiLoadRecord('inventoryitem', id);
if this is changed to:
var item = nlapiLoadRecord('assemblyitem', id); then it only changes assy items.
How do I get it to do both?
// 125630
// After Submit on PO
// Check if multiple vendor is enabled. if not Do nothing.
// After Submit of Purchase Order
function UpdateItemPrice(type)
{
/* Get Item Count.
Check if Update price is checked.
If yes, get Item ID
Get preferred vendor, Update purchase price.
*/
// Check if Multiple vendor feature is enabled.
if (type == 'create' || type == 'edit')
{
var context = nlapiGetContext();
var isFeatureOn = context.getSetting('FEATURE', 'multivendor');
if (isFeatureOn == 'true' || isFeatureOn == 'T')
{
var record = nlapiGetNewRecord();
// Get Vendor id from PO
var vendorId = record.getFieldValue('entity');
var lineCount = record.getLineItemCount('item');
for (var i = 1; i <= lineCount; i++)
{
// Check if the price needs an update
if (record.getLineItemValue('item', 'custcol_633633_updateprice', i) == 'T')
{
// Get id of the item
var id = record.getLineItemValue('item', 'item', i);
// Get the rate being submited
var rate = record.getLineItemValue('item', 'rate', i) ;
// Load the Item
var item = nlapiLoadRecord('inventoryitem', id);
// Get the itemVendor machine count
var vendorCount = item.getLineItemCount('itemvendor');
// Match vendor id from PO to vendor id from Item Vendor machine
for (var j = 1; j <= vendorCount; j++)
{
if (item.getLineItemValue('itemvendor', 'vendor', j) == vendorId)
{
item.setLineItemValue('itemvendor', 'purchaseprice', j, rate)
}
nlapiSubmitRecord(item, false);
}
}
}
}
}
}