Is there a way to FORCE a script to run under a pa...
# suitescript
j
Is there a way to FORCE a script to run under a particular role DYNAMICALLY when called from another script? I have a Suitelet called externally (but only by employees that do actually have NS logins) which will know what user called it (it’s coming in via a slack integration….). This Suitelet then calls a Scheduled Script by way of a
task.create()
. I want the system to check the role of the user that triggered the call, and use that role in the code that executes within the Scheduled Script.
Note that there’s no actual
user
as such to run the script under, so I want to be able to do my own lookup to determine the appropriate role, then somehow say “run this task.create() with role A”
without having to make a separate deployment for every role, obvs
a
hmm this seems awkward, I don't know of anyway to run a task with a specific role 1. users can have multiple roles 2. what are you doing in the script that's role specific?
j
I want to be able to run a global search from Slack, and have it auto-post to slack links to all the matching records
but only want to show record types that that user actually has access to.
I think I’ve found a workaround, I am going to do a lookup for all the record types all their roles grant them access to, and only include results of that type in the response.
m
What about role restrictions (subsidiary etc..)?
j
hm
yeah I might need to worry about that too
that can come later 😉
a
v2
😄
j
we are JUST in the works of starting to do multi-subsidiary stuff now
a problem for future Jen
a
is finding which records roles have access to fairly straight forward then?
j
let record_type_sql =
Copy code
SELECT DISTINCT name
FROM rolepermissions
JOIN employeeroles ON employeeroles.selectedrole = rolepermissions.role
WHERE employeeroles.entity =
+ ns_user_id + ` AND permlevel > 0 ORDER BY name`;
will get names of record types this user has at least view on
and other non-record-type permissions too but those won’t match the GS results anyhow so I’m not too fussed
a
rolepermssions just has records?... aahh okay gotcha
so maybe a dumb question, but if they're just gonna get links in slack to take them to NS to view the records... why not just login and do the global search?!
technically this seems kind of cool, but business use-case? i don't get it
j
we use slack a BUNCH to send links back and forth to each other
thought it might be handy for people in convo to just be like “look up <whatever>“, see all the <matching things>
I dunno, I’m just playing around really
a
lol ok so this is "i think this is cool so I'm doing it" project? nice holiday season project 😄
j
our current integration already turns certain words into links to the matching records (if they match a known pattern e.g. IV12345 for an invoice)
a
idk if it will be a problem put if person A searches with their permissions and sends the link to person B to click they can just get a permission violation if they dont have the permission
still cool I approve ¯\_(ツ)_/¯
a
@jen You can create deployments dynamically before you create your
task
, you are going to have a limited number of roles, therefore you can do something like: • Search for an existing deployment for the user role, if exists then create your task with that deployment, otherwise, create the deployment. • At some point you end up with the deployments you need per role and no more deployments are created.
r
Have you tried logging the user id using the
runtime
module in the scheduled script? To my knowledge, if the suitelet is triggered in the UI and it calls a MR or Sched script, the system passes the user info.
j
it’s not called under a user though, it’s called externally
I have the user id via the integration, just not the role (but that’s ok, I found a workaround)