hey everyone, I've got a question about grabbing d...
# suitescript
m
hey everyone, I've got a question about grabbing data in a Map/Reduce. In my getInputData function, I've got something like this:
var search =  search.create({ ... }); return search
That seems to work, as the context in my Map function is: `{"recordType":null,"id":"552","values":{"GROUP(transactionname)":"some-transaction-name","GROUP(email)":"``some_email@test.com``","GROUP(custbody_procurement_vendor)":{"value":"2350190","text":"I am a Vendor"}}}` With the summary group, I am having difficulty getting the values. I've tried:
var result = JSON.parse(context.value); result.values.getValue({name: 'transactionname', summary: 'GROUP'})
That didn't work, so I have tried different variations of that, like
result.values.getText({...})
,
result.getValues({ ... })
, and even tried to just get the "GROUP(transactionname)" with normal object notation as a string, but nothing seems to work. Thanks for any help!
s
I have typically written out the values in the MAP phase.
You can inspect the results there.
I then use a terinary to supply the value, depending on whether GROUP is used.
n
var revPlanId = res.values["GROUP(internalid)"].value;
var rec = record.load({
type: 'revenueplan', id: revPlanId });
anyways here is an example with group being used
m
thanks @Nicolas Bean . . . is there something different with Map/Reduce vs. a User Event for this. I swear I've gotten
var result = JSON.parse(context.value); result.values.getValue({name: 'transactionname', summary: 'GROUP'})
to work before with group but it may not have been a Map/Reduce
n
I'm not sure to be honest, I haven't tried it in a User Event
s
this might be a bit overkill for a small project, but I had a bunch of code in a shared module that I wanted to be able to use in a user event script, a restlet script, and a map reduce script to retrieve search results, but of course the map phase of Map/Reduce doesn't actually provide a search result object. I used these two functions to allow me to retrieve the values using the same syntax that I would if was actually a search result. There are probably some edge cases it doesn't handle, but it has worked for me for a few different scripts so far.
you could adapt it for the reduce phase with some minor adjustments
m
thank you @scottvonduhn... I'll look over that. It might be useful. Ultimately what I have to do is create/run a search that is going to bring back about 3,000 results, go through through those results, and if certain criteria are met, send an email with some of the data and also that links to a suitelet where the user can take action.
I was first doing this in a Scheduled Script but realized at 3,000 results the Map/Reduce would probably be better. I guess. i am still pretty new with SuiteScript. I go back and forth from SS and SCA dev and haven't gotten settled with SS yet
s
the real benefit of these functions is to make the code from other scripts types more portable to a map/reduce script, given that it really only gives you key-value strings, which aren't too bad for simple searches, but when summary and join are involved, the format of the values gets very ugly. it sounds like you are doing exactly that (porting from scheduled to map/reduce) so it might be worthwhile
👍 1
n
Maybe it'd be simpler to process your search in the getInputData to create an array of JSON objects and return that? That's what I'd typically do, particularly helpful if you are interested in text values for instance and also want to shuffle in other details before the map step.