Fetch the custom list values to the script

To retrieve the custom list in the script, we can utilize a saved search to fetch the list values and store them in an array. This method is used to get the list values dynamically into the scripts.

Here is an example to fetch the custom list ‘Changing Reasons’ whose id is: customlist_price_level_changing_reason.

Each value is pushed into the array ‘reasonsListArray’.

     /**
     * To fetch the price level changing reason list values dynamically from UI
     */
    function fetchChangingReasonsList() {
      try {
        let reasonsListArray = [];
        let changingResonResults = search.create({
          type: "customlist_price_level_changing_reason",
          filters: [
            ["isinactive", "is", "F"],
          ],
          columns: [
            search.createColumn({
              name: "name",
              label: "Name"
            }),
            search.createColumn({
              name: "internalid",
              sort: search.Sort.ASC,
              label: "Internal ID"
            })
          ]
        });
        changingResonResults.run().each(function (result) {
          reasonsListArray.push(result.getValue(changingResonResults.columns[0]));
          return true;
        });
        return reasonsListArray;
      } catch (e) {
        log.debug('error@fetchChangingReasonsList', e)
      }
    }

Leave a comment

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