Function to retrieving Available Items in a Bin Using Inventory Balance Search

  /**
         * Function defined to fetch all the items available in the bin in the corresponding location using inventory balance record
         * @param {Number} bin 
         * @param {Number} location 
         * @returns {Object}
         */
        function findAvailableItems(bin, location) {
            try {
                let binItemCombQtyObj = {}

                var inventorybalanceSearchObj = search.create({
                    type: "inventorybalance",
                    filters:
                    [
                       ["location","anyof", location], 
                       "AND", 
                       ["binnumber","anyof", bin], 
                       "AND", 
                       ["onhand","greaterthan","0"]
                    ],
                    columns:
                    [
                       search.createColumn({
                          name: "binnumber",
                          summary: "GROUP",
                          label: "Bin Number"
                       }),
                       search.createColumn({
                          name: "item",
                          summary: "GROUP",
                          label: "Item"
                       }),
                       search.createColumn({
                          name: "onhand",
                          summary: "SUM",
                          label: "On Hand"
                       }),
                       search.createColumn({
                          name: "available",
                          summary: "SUM",
                          label: "Available"
                       })
                    ]
                 });
                 var searchResultCount = inventorybalanceSearchObj.runPaged().count;
                 log.debug("inventorybalanceSearchObj result count",searchResultCount);
                 inventorybalanceSearchObj.run().each(function(result){
                    // .run().each has a limit of 4,000 results
                    let bin = result.getValue({
                        name: "binnumber",
                        summary: "GROUP",
                        label: "Bin Number"
                    });
                    let item = result.getValue({
                        name: "item",
                          summary: "GROUP",
                          label: "Item"
                    });

                    binItemCombQtyObj[`${bin}-${item}`] = result.getValue({
                        name: "available",
                          summary: "SUM",
                          label: "Available"
                    });
                    return true;
                 });
}

       

Leave a comment

Your email address will not be published. Required fields are marked *