In the client script, we can set the sublist value in the fieldChanged() function.
function fieldChanged(scriptContext) {
try {
let currentRecord = scriptContext.currentRecord;
if (scriptContext.sublistId == ‘item’ && scriptContext.fieldId == ‘location’) {
let item = currentRecord.getCurrentSublistValue({ sublistId: ‘item’, fieldId: ‘item’ });
console.log(“item “, item)
let location = currentRecord.getCurrentSublistValue({ sublistId: ‘item’, fieldId: ‘location’ }); console.log(“location”, location)
let itemTotalValue = itemSearch(item, location);
console.log(“avg cost”, itemTotalValue);
let quantity = currentRecord.getCurrentSublistValue({ sublistId: ‘item’, fieldId: ‘quantity’ }); console.log(“quantity”, quantity)
let costEst = currentRecord.getCurrentSublistValue({ sublistId: ‘item’, fieldId: ‘costestimate’ }); console.log(“cost estimate”, costEst)
let valueCheck = quantity * itemTotalValue;
console.log(“value Check”, valueCheck)
if (itemTotalValue != 0) {
console.log(“inside cond”)
try {
currentRecord.setCurrentSublistValue({ sublistId: ‘item’, fieldId: ‘costestimate’, value: valueCheck, ignoreFieldChange: true });
}
catch (e) {
log.error(“errro@set”, e)
}
}
}
}
catch (error) {
log.error(“error@fieldChanged”, error);
}
}