Checking user role in flow designer

saikumarkak
Tera Contributor

saikumarkak_0-1754892516251.png

i wrote the script that selected user has the admin role the the flow should be continue. here when tesing i am getting this error message. "Error: Cannot read property "variables" from null,Detail: Cannot read property "variables" from null"

saikumarkak_1-1754892695040.png

 

1 ACCEPTED SOLUTION

Viraj Hudlikar
Giga Sage

Hello @saikumarkak 

When I tried with below code in script part where you check and set value of flow variable, I also did same, and it worked for me. Have a look and give try.

//fd_data.trigger.request_item.variables.<variable name>.sys_id;
var a = fd_data.trigger.request_item.variables.affected_user.sys_id;

//checking by passing user sys_id and if it has role admin
var b = gs.getUser().getUserByID(a).hasRole('admin');

//return of value is it true or false.
return b;

 

VirajHudlikar_0-1754897743784.png

VirajHudlikar_1-1754897759579.png

 


If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

View solution in original post

5 REPLIES 5

Mark Manders
Mega Patron

Does the flow run as system user or as user initiating the flow? 

Next to that: you are getting the variable from the trigger record, while you have the requested for in your first action (get variables). Why don't you get it from there?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders ,
Thanks for the response,
flow run as system admin.

you are getting the variable from the trigger record, while you have the requested for in your first action (get variables). Why don't you get it from there? 

you mean can i use getVariables to get the variable value



@Mark Manders ,
can you explain little bit more to understand.

MarkManders_0-1754896164710.png

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark