Any way of getting the result iteration in a map/r...
# suitescript
e
Any way of getting the result iteration in a map/reduce script? The script uses a saved search that returns 1,000 results. Anyway to log a message after every 100 results have been completed?
s
Add the rowNumber to your results and do logic on it.
e
Good call. Thanks @Sandii
Interestingly, rownum is returning the same number for multiple different results, even though all the results are unique
s
If you are return a searchResult object from getInput,
context.key
in your Map stage should be the same as a the row number of the search result
e
This worked!
Copy code
function getInputData() {
            let results = [];
            let mySearch = search.load({
                id: 'customsearch_mr_get_pricing_from_website',
                type: 'item'
            });

            mySearch.run().each(function (result) {
                results.push(result)
                return true;
            });

            return results;

        }
In case anyone else runs into this ---- Instead of returning just the
search.load
portion in the getInputData function, I needed to create an empty array, loop the results and add each to the array, then return the array. Prior to doing this,
context.key
was equal to the internal Id of the item for each search result (not what I was needing)