How to filter the search results using filter function

Create a search to fetch the customers who gave Feedback Response

First get the search using search.create.

Here we removed the customers who gave more than one response from the search results.

// Get the search results               

const searchResults = customrecord_sf_responseSearchObj.run().getRange({ start: 0, end: 1000 });

  // Filter out results where the customer gave a response more than once               

const filteredResults = searchResults.filter((result, index, array) => {               

    const customerId = result.getValue({ name: ‘custrecord_sf_res_customer’ });               

    const responseCount = array.reduce((count, currentResult) => {             

          if (currentResult.getValue({ name: ‘custrecord_sf_res_customer’ }) === customerId) {                         

  count++;                     

  }                       

return count;                 

  }, 0);               

return responseCount === 1;             

});
             

  return filteredResults;

Leave a comment

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