Never mind. I guess creating the columns with a cu...
# suitescript
j
Never mind. I guess creating the columns with a custom name in the script does work. I think I was just referencing them wrong:
Copy code
nSearch.createColumn({
    name: 'formulanumeric1',
    summary: 'MIN',
    formula: 'CASE WHEN {memberitem.inventorylocation} = {memberitem.preferredlocation} THEN NVL({memberitem.locationquantityavailable}, 0) END'
})
🫡 1
m
My preferred way of handling this is to set a label for each column and use a helper to convert search results to a simple object keyed by the label
Copy code
/**
   * Run a search and retrieve search results as a plain JSON object (keyed by column label)
   *
   * @param {import("N/search").Search} savedSearch A Saved Search object
   * @returns {{ [key: string]: string | boolean | string[] }[]} All results from the saved search,
   *   as object keyed by column label
   */
  function getAllSearchResults(savedSearch) {
    const results = [];

    const pagedData = savedSearch.runPaged({ pageSize: 1000 });

    pagedData.pageRanges.forEach((pageRange) => {
      const currentPage = pagedData.fetch({ index: pageRange.index });
      currentPage.data.forEach((result) => {
        const resultObject = {};
        result.columns.forEach((column) => {
          resultObject[column.label] = result.getText(column) || result.getValue(column);
        });
        results.push(resultObject);
      });
    });

    return results;
  }