I'm creating a beforeSubmit
script that needs to add a new line item to a sublist and commit both.
I've tried use selectLine
, insertLine
and selectNewLineItem
, but no one worked adding the line during the record save:
record.insertLine({
sublistId: "item",
line: 1
});
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 3919,
ignoreFieldChange: true,
forceSyncSourcing: true,
fireSlavingSync: true
});
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 1,
fireSlavingSync: true
});
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value: valorProd1,
ignoreFieldChange: true,
forceSyncSourcing: true,
fireSlavingSync: true
});
record.commitLine({
sublistId: 'item'
});
Any are appreciated!
insertLine
only inserts line and does not selects it, whereas to use setCurrentSublistValue
you need to select the line first. So replacing insertLine
with selectNewLine
should do the trick for you.
You can check this out for further reading.