we have a map/reduce script that creates IF from s...
# suitescript
s
we have a map/reduce script that creates IF from sales orders for lot controlled items we run a search to get the valid lot numbers, a current bug we have is if the order is for 10 and the first lot qty has 2 it will just choose even if the next lot has 1000, how can I change my script to go to the next lot
Copy code
inventoryitemSearchObj.run().each(function (result) {
          var quantity = result.getValue({
            name: "quantityavailable",
            join: "inventoryNumber",
          });
          var qtysubmit = Math.min(quantitycommitted, quantity);
          /// var submitqty =  quantitycommitted < quantity ? quantitycommitted : quantity;
          var lotNumber = result.getValue({
            name: "internalid",
            join: "inventoryNumber",
          });
          var subList = fulfillmentRecord.getSublistSubrecord({
            sublistId: "item",
            fieldId: "inventorydetail",
            line: i,
          });
          subList.setSublistValue({
            sublistId: "inventoryassignment",
            fieldId: "quantity",
            line: 0,
            value: qtysubmit,
          });
          subList.setSublistValue({
            sublistId: "inventoryassignment",
            fieldId: "issueinventorynumber",
            line: 0,
            value: lotNumber,
          });
          return true;
        });
b
depends on what your lot picking strategy is
usually for these kind of scripts you just assign in the order of your search results
so if you had 2 available in lot 1 and 1000 in lot 2
then you would assign 2 from lot 1 and 8 in lot 2
if you only ever wanted to assign 1 lot per item, then you want to return true before you set all those sublist fields if the lost doesnt have enough quantity
s
we can use multiple lots per item per order so option one will work fine
b
then you cant keep on setting the first line of the inventory assignment
and you need to decrease the quantity committed by the quantity set on the previous lines of the inventory assignment
using the previous example, the quantity committed would be 10 on the first iteration of your loop, and should be 8 on the second iteration since you assigned 2 on the first one
s
i see ok thanks @battk you gave me what to think about and pointed me in the right direction
b
usually these types of script favor doing your search ahead of time for all the items on your transaction
it makes it easier to handle edge cases where there are lines with the same item
s
This is a map/reduce for our daily orders which can be a many different sku
b
it usually becomes even more important to do the search once for all items on your transactions the more items there are
s
I guess I'm not understanding make a search like a pick list
b
if your item fulfillment has 3 item rows, it costs less points to do 1 search to get all the lots of the 3 items
s
This is for 1000 different orders
b
vs 3 searches for the lots of each individual item
it becomes more important if you have to handle edge cases like your item fulfillment has 3 item rows, with 2 of those rows having the same item
in which case its basically wrong to do the 2 individual searches since assigning lots to the first duplicate affects which lots are available in the second