Sorting the result in the saved search

The client would like to set the child waybill number(Which is fetched as a part of integration ) to the carton details record based on the order.

This can be accomplished by sorting the saved search results based on the carton ID.

     /**

      * Function to fetch the carton internal id

      * @param {number} id -internal id of item fulfillment record

      * @returns {object} object containing carton id

      */

     function fetchCartonId(id) {

         try {

             let itemfulfillmentSearchObj = search.create({

                 type: “itemfulfillment”,

                 filters:

                     [

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

                         “AND”,

                         [“internalid”, “anyof”, id],

                         “AND”,

                         [“cogs”, “is”, “F”],

                         “AND”,

                         [“shipping”, “is”, “F”],

                        “AND”,

                        [“mainline”,“is”,“T”]

                     ],

                 columns:

                     [

                          search.createColumn({

                              name: “internalid”,

                              join: “CUSTRECORD_IF_CARTON_LINK”,

                              label: “Internal ID”

                               }),

                              search.createColumn({

                              name: “custrecord_if_carton_no”,

                              join: “CUSTRECORD_IF_CARTON_LINK”,

                              sort: search.Sort.ASC,

                              label: “Carton No.”

                             })

                     ]

             });

             let searchResultCount = itemfulfillmentSearchObj.runPaged().count;

             let cartonIdSpecificObj = [];

             if (searchResultCount > 0) {

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

                     let cartonsId = result.getValue({

                         name: “internalid”,

                         join: “CUSTRECORD_IF_CARTON_LINK”,

                         label: “Internal ID”

                     });

                     cartonIdSpecificObj.push(cartonsId)

                     return true;

                 });

             }

             return cartonIdSpecificObj;

         } catch (error) {

             log.error(“error@fetchCartonId”, error)

             submitErrorData(error,ifRec)

         }

     }

Leave a comment

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