First we need to enable the ‘landed cost per line’ then set the value using script.
let newRec = scriptContext.newRecord;
let landedCostField = newRec.getSublistSubrecord({
sublistId: ‘item’,
fieldId: ‘landedcost’,
line: itemLine
});
// Set the landed cost in item line level
landedCostField.setSublistValue({
sublistId: ‘landedcostdata’,
fieldId: ‘costcategory’,
value: 2,
line: 0
});
landedCostField.setSublistValue({
sublistId: ‘landedcostdata’,
fieldId: ‘amount’,
value: itemLandedCost,
line: 0
});