i am writing a MR script in which i have a saved s...
# suitescript
v
i am writing a MR script in which i have a saved search which returns 3000+ results. i need to create a journal record based on the transactionperiod and Subsidiary. totally there are 4 subsidiaries and 15 transactionperiods. how could i do that in scripting? i dont get any logic as the number of records is very high. could anyone please help ?
r
You can iterate the search in input stage and create a dictionary / JSON itself from it which you can return to the map stage for creating each JE. Then in each map stage you can create 1 JE for each subsidiary, accounting period combination. JSON could look like this: {Subsidiary_accountingPeriod : Details} Details(whatever data you need) could be a dictionary or an array of the dictionary itself which you will be able to iterate in your map stage.
v
how to do the iteration in the input stage?
could you please share any code if you have?
n
There's several standard JavaScript approaches to iterate the results, it's just an array of search results.
v
i know the for loop , i mean to say the iteration in the input stage i am not aware
n
Raghav said : "You can iterate the search in input stage" That's the array we're both talking about...
Iterate your search results building something you can pass forward to the map.
v
i dont know how to do this on the inputstage. if you have any code; please share
one more thing actually i have 3027 results of saved search while running in UI. but when i get the count in script it returns 1283 results. is it related to the limitations?
r
in inputStage I believe what you are doing currently is creating a search, and returning the searchObject. What I am suggesting is do the search in input stage. iterate the search and from that search create your own JSON with whatever logic you want to have. And return that JSON. For eg: Just create a map reduce script. In input stage return the below,
Copy code
return obj = {
   1: {"details" : "map1}",
   2: {"details" : "map2"}
}
Then in mapStage, just log context.key and context.value and see the output Each key will run in its map stage will run as its own key value pair. Once you understand that, you can go around building your own logic for creating the JSON in input stage. You can create JSON however to your linking, just note that each key in the JSON will run as an individual map.
does your search have date filters? If yes, you will have to do timezone handling as Netsuite Server Side scripts will run in PST timezone. So new Date(), today, etc in the UI might be 05/12/2023. But in script it can differ. To check this in UI, You can change your prefered timezone to PST time, and then create 1 more search with the same filters. And see the result count.
v
so far i dont get this error, now i get SSS_INVALID_SRCH_OPERATOR on returning the savedsearch to map stage. what is the reason for this?
r
Can you share your code, will not be able to identify like this.
v
function getInputData(){ log.debug('getting inputdata'); var vatRatioSavedSearch = search.load({ id : 'customsearch_adj_vat_ratio_lines' }); log.debug('vatRatioSavedSearch',vatRatioSavedSearch); log.debug('length',vatRatioSavedSearch.runPaged().count); /*vatRatioSavedSearch.run().each(function (result) { log.debug('result',result); });*/ return vatRatioSavedSearch; }
r
are you getting log for length? if yes, can you see whether this search is working in UI?
v
no,
but in the UI its working fine
r
can you export your search through saved search extension and mind sharing here? https://chrome.google.com/webstore/detail/netsuite-search-export/gglbgdfbkaelbjpjkiepdmfaihdokglp
v
hi raghav
you told me to "iterate the search and from that search create your own JSON with whatever logic you want to have. And return that JSON."
i get this error SyntaxError: Unexpected token s in JSON at position 0 [at JSON.parse (native), at Object.getInputData