hi, I have a map reduce script, in getInputData i ...
# suitescript
d
hi, I have a map reduce script, in getInputData i have this
Copy code
const orSearch = search.load({ id: 'customsearch_ps_emptybrand' });
        const inputData = [];
        let rows = orSearch.run().getRange(0, 1);
        log.debug('rows', rows);
        for (let i in rows) {
            const internalid = rows[i].getValue({ name: 'internalid', summary: 'GROUP' });
            inputData.push({ internalid });
        }
        log.debug('inputData', inputData);
        return inputData;
If i run the saved search from Netsuite UI, i can see 15 results, but in the map reduce above,
rows
and
inputData
are showing empty array I can confirm that the saved search that i'm using in the script and the one i run in UI is the same. Any idea what am i missing here ?
e
This probably isn't too helpful, but I don't see anything wrong with your code, and testing the exact same code in my account in the console works as expected. It shouldn't behave any differently in a Map/Reduce, either, so I don't think that's it. FWIW
for..in
is not advised for iterating over Arrays.
for..of
,
forEach
, and other iterators like
map
are preferred.
d
hi thanks for replying and testing on your side eric
could it be because of permission or restriction ?
i saw in the same Netsuite account, in Inventory Adjustment, different Form will filter only specific items on the line level
e
Maybe, if it's a Private Search?
d
could it be the same thing for this ?
it was private, but then i have updated it to public, no luck same thing
e
Have you tried a different search?
Maybe a simple one with no filters of formula?
d
hmm not yet, yup maybe i should do try that
let me do a quick one now
wow, in sandbox, same script, same saved search and it works
1
hmm still i have to get this work in production as well, no idea at all
maybe i'll try to delete the saved search and recreate
not sure what i'm doing, but i cannot think of any other thing now
e
Check for errors. Try/catch log the error
☝️ 1
e
The M/R is likely swallowing any errors and shoving them down to
summarize
. A
try..catch
like Lee suggests might help you surface the error
d
thanks lee and eric, i just removed the old saved search, and create a new one, exactly the same
and it's working now, omg. Maybe the previous one somehow corrupted
Yup i still have the backup of the old saved search, will try to put try and catch on the MR and see if i can find anything
k
Why wouldn't you just return the search in the getInputData stage and let the Map/Reduce script handle the values?
Copy code
function getInputData() {
            const search = nsSearch.load({
                id:'customsearch_ps_emptybrand'
            });

            return search;
        }
s
or even better, return an object literal indicating which search to run
1
e
Not sure we have nearly enough context to prescribe "better" approaches here.
s
well, I maintain that returning the object literal is objectively 'better' than the code prior which just loads and returns a search object.
e
I agree on that, but in regards to the OP, we're just guessing
educated guesses, of course 🙂
👍 1
f
Maybe pass the search as a parameter.
d
Thanks Shawn, you're right, normally i will return the search object, but for my case i need to return paginated result, i don't want the whole data to be processed at once, because the saved search contains a lot of records and we have concern that this MR will take too long to run and blocking other MR / scheduled script.