so possible workaround ideas would be: - is there ...
# suitescript
so possible workaround ideas would be: • is there any way of running a map reduce in other role than administrator? (that could allow us to have multiple deployments one for each role) • is there a way of running a saved search under a specific role from code?
Yes, you can run as role on the m/r deployment. You have a few options how you set that. • Create a new deployment for each role you want to run as • Have the calling script edit the deployment with the role before executing If you can, I would create a new deployment for each role, maybe identify those deployments by the role ID so you know which one to call.
Hi, are you 100% sure? because when creating a deployment for map reduce, it does not let you select the role, it goes straight to administrator
message has been deleted
Interesting. I don't think I ever realized that on the M/R script deployments. I know you can set it for other script types because I do this in one of my install scripts>
Copy code
                        type: 'scriptdeployment',
                        id: results[0].primarykey,
                        isDynamic: true
                    .setText({fieldId: 'runasrole', text: 'Administrator'})
Apparently you cannot change M/R role
you might have to call a suitelet that uses the run as role
yet another reason to not use M/R scripts 🙂
the problem is that we have like 2000 lines of code in that Map reduce, moving it to something else would be imposible
also, the amount of data that it needs to handle makes impossible to use a scheduled script (the reason why we used map reduce to begin with)
and even if i call the MR from a suitelet that runs under a role, the MR will run under administrator anyway
a great solution would be if netsuite allowed you to run a search under a specific role, but that also its not possible as far as i know
How about using a scheduled script to run the saved search and save the results to a file and then pass that fileId to the M/R script for processing?
we are running 3 saved searches on parallel and composing data based on it, it would be very difficult
So in your mr script are you saying that running the saved searches in parallel and combining data is done in the map or reduce stage?
Is getting the exchange rate and converting the currency values not an option?
@Eric B we are running a map reduce, we have a set of queries that are executed multiple times with different filters, both in the get and in the map
@Sandii it would be, but we are doing Group/sum on the saved searches, so we dont have the transactions date in order to get the correct exchange rate from the consolidated exchange rate table
i guess i am out of luck on this issue right? 🙂
If you’re executing a set of queries multiple times using different filters in the getinput stage that wouldn’t run in parallel so I don’t see why you can’t use a scheduled script to do that part to retrieve the data you need. Architecturally speaking, you’re better off constructing your data object in the getinput stage and then grouping them in the map stage before you run your processing in the reduce stage.
💯 1
I ran some tests and when you set a Suitelet to run as role it executes the search as that role. You would have to use N/HTTPS and set it was externally available which isn't ideal. I would suggest using a Restlet instead so the tokens used would be tied to the roles. That is the only solution I can think of short of what Eric mentioned with the search results being saved as a file.
You can create multiple deployment of the same map/reduce script and create a search script parameter (list/record, saved search) where you change the criteria of each search for each subsidiary currency. So basically each deployment of the map/reduce points to a different saved search (with different results based from the criteria) to process at the getInputStage by doing a search.load (instead of hard coding the search). Hope that make sense. Ex: customdeploy_mr_subA_usd —> transaction search (where all trx are from subA and usd) customseploy_mr_subB_cad —> transaction search (where all trx arefrom subB and cad)
you cannot specify the conversion rate on the amount field by any criteria, it depends only of the current role
There is an amount foreign (amountfx) I believe that returns the converted amount.
fx amount, it returns the converted amount in the original transaction currency, which is no good if you have multiple currencies it just sums all the numbers without matter of the currency and it makes a mess (already tested it)
you might probably need a formula column to convert the amount then, I think there is a conversion rate that you can use to do that, or create a related custom table for the corresponding transaction or fields to store the converted amount for each currency (UE)
or use the N/currency module to convert the amount at the M/R level if you don’t want to use the approach of custom field or record.
currency consolidation can be a lot more complicated than multiplying the amount by an exchange rate
you might luck out in that the account is super simple and you can get away with some formula, but in general its going to be a pain trying to convert the amounts to a different currency accurately
even determining which currency you should convert to is not simple, there are 4 different options for a role to determine which subsidiaries the role has access to
best chance to do this accurately is to run the map/reduce under a different role
both scheduled scripts and map/reduce scripts operate under the same role and user restrictions
when executed manually from the ui or on a schedule, the user will be the system using the administrator role
which will by default use the currency of the root subsidiary
when executed using N/task, the script will run using the current user and role (or whatever role specified on the deployment of the script running N/task)
it more useful to know this information when it comes to user specific preferences like date/time, but you can use it to run your map/reduce using different roles