We have a Map/Reduce script that is essentailly us...
# suitescript
s
We have a Map/Reduce script that is essentailly using the getInputData stage to create an array of intergers (e.g. page numbers) that we return. Then, in the Map stage, we inject the context.value into a URL parameter so we can paginate through the enpoint results. To my issue, it appears the Map stage is processing the first endpoint object result 100 times for each page. To my question, is there an issue with the script returing an array to the map stage? Or, do i need to look elsewhere? Any help would be appreciated.
Copy code
getInputData() {
  var pages = 5000;
  var pageNumbers = []
 
         for (var int = 0; int < pages; int++) {
             pageNumbers.push(int);
         }
 
         //returns [0,1,2,3...5,000]
         return pageNumbers;
}

function map(context) {
         try{
 
     	    var pageNumber = JSON.parse(context.value);
            finalEndpoint += '&param1=*&pageOffset='+pageNumber+'&resultRecordCount=100&f=json&exceededTransferLimit=true.....'

//some code
}
e
There shouldn't be any issue returning an Array. Have you logged the value of
pageNumber
or
context.value
before trying to use it? FWIW your Array doesn't contain any JSON strings, though, so there's no need to
JSON.parse
in the
map
stage.
s
Thank you! Yes, the pageNumber log looks correct. Oddly, when I run the script through the debugger (forcing to map stage) and hard-coding the pageNumber , it iterates through all the records on the enpoint page correctly, which made me question the array. I’ve always returned a search object to map. This was helpful, so thank you!