-1

There is a customized transaction line field which is named as "custcol_so_line_id". Its value should be the same as the ID of the sublist line.

The code is as follows:

function beforeSubmit(context) {

    var rec = context.newRecord;

    var lineItemID = rec.getSublistValue({
        sublistId: 'item',
        fieldId: 'id',
        line: 1
    });

    rec.setSublistValue({
        sublistId: 'item',
        fieldId: 'custcol_so_line_id',
        value: lineItemID
    });
}

return {
    beforeSubmit: beforeSubmit
}

After clicked the Save button in Sales Record. The sales record should display SO_12345 in the customized line field "cuscol_so_line_id". But it didn't and shows the error as follows: load: Missing a required argument: id for the code var salesRec = record.load({...

If I change the entry point to "afterSubmit", then the SO_12345 appears.

Can't we update the record before it is submitted? How to find the id for line in beforeSubmit function?

skyline
  • 443
  • 9
  • 31

3 Answers3

1

In Before Submit Function you wont get the record ID . This is causing the error you mentioned .

In after Submit you are getting the Record Id since it is AFTER saving the record.

Edwin Thomas
  • 466
  • 4
  • 16
1

What you're trying to get with salesRec is the same as what you already have with rec. However, you cannot load salesRec, as that has not been written to the database at the point when beforeSubmit is fired. You need to make the changes to rec instead.

function beforeSubmit(context) {

    var rec = context.newRecord;

    rec.setSublistValue({
        sublistId: 'item',
        fieldId: 'custcol_so_line_id',
        value: 'SO_12345',
        line: 1
    });
}

return {
    beforeSubmit: beforeSubmit
}
Krypton
  • 4,394
  • 2
  • 9
  • 13
0

I found the URL is as this (domain).netsuite.com/app/accounting/transactions/salesord.nl?whence= which there is no sales record id inside.

Does that mean the ID for record is not generated? If yes, then the line id maybe not defined yet as well since its prefix will RECORD-ID_LINE-INDEX, e.g. 2100627_2, which 2100627 is the record ID and 2 is the line index.

skyline
  • 443
  • 9
  • 31