https://netsuiteprofessionals.com logo
#suitescript
Title
# suitescript
a

alien4u

04/12/2022, 6:21 PM
Anyone found a way to get inventory details data on beforeSubmit?
b

battk

04/12/2022, 6:39 PM
the normal method outlined in SuiteScript 2.x Scripting Subrecords should work
a

alien4u

04/12/2022, 6:42 PM
On create and beforeSubmit that details subrecords lines are empty, sadly...
b

battk

04/12/2022, 6:45 PM
what does your code look like?
a

alien4u

04/12/2022, 6:55 PM
Copy code
/**
 * Loops through the lines and get the lines Inventory Details if any.
 *
 * @param {Object} pRec
 *
 * @return {Object}
 * */
const getInventoryDetails = (pRec) => {

    const nLines = pRec.getLineCount({
        sublistId: 'item',
    });

    const oLinesData = {};
    for (let nLine = 0; nLine < nLines; nLine++) {

        const sReceivedLine = pRec.getSublistValue({
            sublistId: 'item',
            fieldId: 'itemreceive',
            line: nLine
        });

        if (!sReceivedLine) {

            continue;
        }

        const sOrderLine = pRec.getSublistValue({
            sublistId: 'item',
            fieldId: 'orderline',
            line: nLine
        });

        const sLineItem = pRec.getSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            line: nLine
        });
        const sLineQty = pRec.getSublistValue({
            sublistId: 'item',
            fieldId: 'quantity',
            line: nLine
        });

        const sInventoryDetailAvailable = pRec.getSublistValue({
            sublistId: 'item',
            fieldId: 'inventorydetailavail',
            line: nLine
        });

        const oInventoryDetailsData = [];
        if (sInventoryDetailAvailable === 'T') {

            const oDetailRec = pRec.getSublistSubrecord({
                sublistId: 'item',
                fieldId: 'inventorydetail',
                line: nLine
            });

            const nDetailLines = oDetailRec.getLineCount({
                sublistId: 'inventoryassignment'
            });

            for (let nDetailLine = 0; nDetailLine < nDetailLines; nDetailLine++) {

                const oDetailData = {};
                oDetailData['DETAIL'] = oDetailRec.getSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'internalid',
                    line: nDetailLine
                });
                oDetailData['BIN'] = oDetailRec.getSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'binnumber',
                    line: nDetailLine
                });
                oDetailData['QTY'] = oDetailRec.getSublistValue({
                    sublistId: 'inventoryassignment',
                    fieldId: 'quantity',
                    line: nDetailLine
                });

                oInventoryDetailsData.push(oDetailData);
            }
        }

        oLinesData[sOrderLine] = {
            ITEM: sLineItem,
            QUANTITY: sLineQty,
            DETAILS: oInventoryDetailsData
        };
    }

    return oLinesData;
}
The same code works properly on afterSubmit if I load the record...
b

battk

04/12/2022, 7:04 PM
way too complicated to be checking if the inventory detail is present
Copy code
log.debug("details", context.newRecord.getSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail', line: 0}))
choose a line which actually has an inventory detail on it
a

alien4u

04/12/2022, 7:05 PM
Copy code
if (sInventoryDetailAvailable === 'T') {
Is that complicated ^^^ ?
b

battk

04/12/2022, 7:05 PM
not really the recommended way, but you have way too much code just to be checking if you can get inventory details
a

alien4u

04/12/2022, 7:06 PM
I'm gathering the inventory details data...
b

battk

04/12/2022, 7:06 PM
log one inventory detail
graduate to getting its individual fields
a

alien4u

04/12/2022, 7:07 PM
I would have transactions with multiple lines and some of those lines may or may not have inventory details data, I need to get the inventory details data, on beforeSubmit on CREATE the code above is unable to get inventory details data...
afterSubmit it gets the data just fine...
b

battk

04/12/2022, 7:07 PM
Record.hasSublistSubrecord is the recommended way to check the existance of a subrecord
👍 1
though there is too much code to tell if that is where your actual problem is
👍 1
Copy code
log.debug("details", getInventoryDetails(context.newRecord))
is outputting
Copy code
{
  "1": {
    "ITEM": "120",
    "QUANTITY": 1500,
    "DETAILS": [
      {
        "DETAIL": -1,
        "BIN": "1",
        "QTY": 1500
      }
    ]
  }
}
which record are you doing this on?
a

alien4u

04/12/2022, 7:58 PM
Item Receipt
b

battk

04/12/2022, 8:27 PM
that log was from an item receipt
a

alien4u

04/12/2022, 8:28 PM
On create and beforeSubmit and you are receiving less than the quantity on the PO?
b

battk

04/12/2022, 8:28 PM
received 1500/2000
on create
a

alien4u

04/12/2022, 8:32 PM
Well the only thing different is my PO is being used in order management, order allocation.
b

battk

04/12/2022, 8:42 PM
im not sure if supply allocation is something that can be turned on or off
im not really risking it on my test account