Anyone found a way to get inventory details data o...
# suitescript
a
Anyone found a way to get inventory details data on beforeSubmit?
b
the normal method outlined in SuiteScript 2.x Scripting Subrecords should work
a
On create and beforeSubmit that details subrecords lines are empty, sadly...
b
what does your code look like?
a
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
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
Copy code
if (sInventoryDetailAvailable === 'T') {
Is that complicated ^^^ ?
b
not really the recommended way, but you have way too much code just to be checking if you can get inventory details
a
I'm gathering the inventory details data...
b
log one inventory detail
graduate to getting its individual fields
a
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
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
Item Receipt
b
that log was from an item receipt
a
On create and beforeSubmit and you are receiving less than the quantity on the PO?
b
received 1500/2000
on create
a
Well the only thing different is my PO is being used in order management, order allocation.
b
im not sure if supply allocation is something that can be turned on or off
im not really risking it on my test account