2

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!

Jimi
  • 29,621
  • 8
  • 43
  • 61

1 Answers1

2

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.

Avi
  • 2,014
  • 1
  • 9
  • 21
  • Thanks for the answer but i still get an error... something like this: " Cannot find function selectNewLine in object standard record." That's my record declaration: record = context.newRecord; – Guilherme Alcantara Jul 22 '19 at 12:04
  • 1
    Could you check if your record is in dynamic mode? To check is record in in dynamic mode, use `nsRecord.isDynamic`. If your record is not in dynamic mode you cannot use `selectLine` or `setCurrentSublistValue` and you will have to use `setSublistValue` in conjunction with `insertLine`. – Avi Jul 22 '19 at 12:36