Hi, I try to change quantity in line in item recei...
# suitescript
r
Hi, I try to change quantity in line in item receipt by UE script in beforeLoad() function. If quantity (100) more than quantity remaining (50), value quantity = 50, i need quantity = 100. But i can open item receipt and change quantity manually.
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/search', 'N/record', 'N/task'],
function(search, record, task) {
function beforeLoad(context) {
var record = context.newRecord;
if (context.type !== context.UserEventType.CREATE) return;
var itemCount = record.getLineCount({
sublistId: 'item'
});
for (var i = 0; i < itemCount; i++ ) {
record.setSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 100,
line: i
});
}
}
return {
beforeLoad: beforeLoad
};
});
s
Before load is generally not for changing values on fields/sublists, this should be handled beforeSubmit most likely, or in some sort of workflow action while the record is submitted.
r
I use before load because i need to show quantity to user
a
@Rodion beforeLoad is not designed or recommended to change values. You can do what you need with a Client Script after the page load.