Reputation: 57
I am currently watching a lot of tutorials and doing a lot of research on SuiteScript 2.0
But before I get into this I want to ask a fundamental question.
Can I edit a field on a particular record type with a script that runs on a different record type.
For example
I have a custom field on my Inventory Item Page. (Item Record)
I want to run a script from Goods Receipt Note (Transaction Record)
So that when the goods receipt note is saved it amends a custom field on the item page.
Is this possible?
Thank you
Upvotes: 0
Views: 981
Reputation: 77
function beforeSubmit(context) {
var new_rec = context.newRecord;
var item_count = new_rec.getLineCount({
sublistId: "item"
});
for (let i = 0; i < item_count; i++) {
var item_id = new_rec.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: i
});
var avgCost = search.lookupFields({
type: "inventoryitem",
id: item_id,
columns: ['averagecost']
}).averagecost;
var updateAvgCost = record.submitFields({
type: record.Type.INVENTORY_ITEM,
id: item_id,
values: {
custitem1: Number(avgCost).toFixed(2)
}
});
}
Upvotes: 0
Reputation: 15447
Generally not a problem as long as the role the script is being run under has write access to the item.
The main thing is transactions can tend to have many lines and if you are updating your items one-by-one you can run into script governance issues.
Upvotes: 1