Jared Fraley
11/17/2022, 5:00 PMdefine(["N/record", "N/search"],
function (record, search) {
function execute(scriptContext) {
const searchObj = search.load({ id: "customsearch_no_3_way_match" }) //load the saved search
searchObj.run().each(function (result) {
const poID = result.getValue(result.columns[2]);
const poLN = result.getValue(result.columns[5]);
const item = result.getText(result.columns[4]);
const poRate = Number(result.getValue(result.columns[6]));
const irID = result.getValue(result.columns[8]);
const irLN = result.getValue(result.columns[11]);
const irRate = Number(result.getValue(result.columns[12]));
const bID = result.getValue(result.columns[14]);
const bLN = result.getValue(result.columns[17]);
const bRate = Number(result.getValue(result.columns[18]));
log.debug({
title: poID,
details: "Item: " + item + " | poID: " + poID + " | poLN: " + poLN + " | poRate: " + poRate + " | irID: " + irID + " | irLN: " + irLN + " | irRate: " + irRate + " | bID: " + bID + " | bLN: " + bLN + " | bRate: " + bRate
});
try {
if (bRate != poRate) {
log.debug({
title: poID,
details: 'bRate != poRate'
});
const po = record.load({
type: record.Type.PURCHASE_ORDER,
id: poID
})
po.setSublistValue({
sublistId: 'item',
fieldId: 'rate',
line: (poLN -1),
value: bRate
});
po.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
}
if (bRate != irRate) {
log.debug({
title: irID,
details: 'bRate != irRate'
});
const ir = record.load({
type: record.Type.ITEM_RECEIPT,
id: irID
})
ir.setSublistValue({
sublistId: 'item',
fieldId: 'rate',
line: (irLN - 1),
value: bRate
});
ir.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
}
}
catch (e) {
log.error({
title: poID,
details: e
});
}
return true;
});
}
return {
execute: execute
};
});
Stuart Anderton
11/17/2022, 5:07 PMehcanadian
11/17/2022, 6:04 PMreptar
11/17/2022, 6:48 PM