Guilherme Alcantara
Guilherme Alcantara

Reputation: 47

How can I add a line item to sublist via beforeSubmit event?

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!

Upvotes: 2

Views: 4813

Answers (1)

Avi
Avi

Reputation: 2069

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.

Upvotes: 2

Related Questions