How to get a unique values from a search without using mainline in a transaction

function getItemFulfillments(salesOrderId, itemIds) {

      let itemfulfillmentSearchObj = search.create({

        type: “itemfulfillment”,

        settings:[{“name”:“consolidationtype”,“value”:“ACCTTYPE”}],

        filters:

        [

          [“type”,“anyof”,“ItemShip”],

          “AND”,

          [“createdfrom”,“anyof”,salesOrderId],

          “AND”,

          [“item”,“anyof”,itemIds]

        ],

        columns:

        [

          search.createColumn({

           name: “internalid”,

           summary: “GROUP”,

           label: “Internal ID”

          })

        ]

       });

       let searchResultCount = itemfulfillmentSearchObj.runPaged().count;

       log.debug(“result count”, searchResultCount);

       let ifArray = [];

       if (searchResultCount > 0) {

        itemfulfillmentSearchObj.run().each(function (result) {

           ifArray.push( result.getValue({ name: “internalid”,

            summary: “GROUP”,

            label: “Internal ID” }))

           

           // .run().each has a limit of 4,000 results

           return true;

         });

       }

       return ifArray;

     }

Leave a comment

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