I am running this adhoc search and then mapping it...
# suitescript
s
I am running this adhoc search and then mapping it to object, I know the result in UI has 2 records, but when I log the poList before returning i only get 1 result. I also tried to log the page and I can see in the pagedData that the results there are being pulled from the search
Copy code
const poSearchObj = search.create({
      type: "purchaseorder",
      filters:
      [
         ["mainline","is","T"], 
         "AND", 
         ["type","anyof","PurchOrd"], 
         "AND",
         ["custbody_adf_sp_mainpo","anyof", id], 
      ],
      columns:
      [
         search.createColumn({name: "tranid", label: "Supplement PO"}),
         search.createColumn({name: "custbody_adf_sp_mainpo", label: "Main PO"}),
         search.createColumn({name: "entity", label: "Vendor"}),
         search.createColumn({name: "statusref", label: "Status"}),
         search.createColumn({name: "amount", label: "Amount"})
      ]
   });
   const poList = {}

   const pagedData = poSearchObj.runPaged({ pageSize: 1000});
   log.debug('PO Paged Data', pagedData);
   let page;
   for (let idx = 0; idx < pagedData.pageRanges.length; idx++) {
       page = pagedData.fetch(pagedData.pageRanges[idx]);
       page.data.forEach(row => {
           poList['supplemental_po'] = row.getValue('tranid');
           poList['main_po'] = row.getValue('custbody_adf_sp_mainpo');
           poList['vendor'] = row.getText('entity');
           poList['status'] = row.getText('statusref');
           poList['amount'] = row.getValue('amount');
       })
      }

   return poList

  }
a
Does your search in the UI also has
mainline
= true?
s
It does, the code here is from the Export as Script extension.
in the UI it doesn’t have the internal ID filter, as the search is being used in a sublist
a
I see your problem...
This is an object
const poList = {}
poList['supplemental_po'] = row.getValue('tranid');
You are overwriting, you would not be able to see both results.
const poList = []; poList.push({ supplemental_po: row.getValue('tranid') } )
s
so it should be push? i’m used to having it as an array but since i’m using this as addCustomDataSource, hence I tried to make it as an object
if I do make it as an array, the addCustomDataSource doesn’t accept it anymore
e
You can then just wrap the Array in an arbitrary object to satisfy `addCustomDataSource`:
Copy code
const purchaseOrders = {
  list: poList
}