- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2019 02:50 AM
Hi,
After group approval it goes for the license team approval. if user did not have same roles.
example :adela.cervantsz has role scrum_user and when we are adding any group need to check user has roles not only one role any roles need to check from any group.
If found same roles need to bypass it to next activity and if did not found need to go for license team approval. So, license team will add the roles.
Below script i used to check the same, but not working.
answer = ifScript();
function ifScript() {
var x=current.variables.select_name;
x=gs.getUserID();
var y=current.variables.select_group;
var ge =new GlideRecord('sys_user_has_role');
ge.addQuery('user',x);
ge.query();
while(ge.next())
{
var gr=new GlideRecord('sys_group_has_role');
gr.addQuery('group',y);
gr.addQuery('role',ge.sys_id);
gr.query();
if(gr.next()) {
return 'yes';
}
}
return 'no';
}
below is the workflow.
Could you please help me.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2019 02:57 AM
Hi Sai,
Can you explain with an example?
Is the script not working as expected?
Are you saying the select_name variable has some user
if that user has many roles say A,B,C
and now you want to check if the group selected in select_group variable has any of those role then return yes else return no
why you are using gs.getUserID() if you want to check role for select_name user?
update code as below
also ge.role will give you role sys_id while comparing in sys_group_has_role
answer = ifScript();
function ifScript() {
var x = current.variables.select_name; // I assume select_name is a reference variable
// x=gs.getUserID();
var y=current.variables.select_group;
var ge =new GlideRecord('sys_user_has_role');
ge.addQuery('user',x);
ge.query();
while(ge.next())
{
var gr=new GlideRecord('sys_group_has_role');
gr.addQuery('group',y);
gr.addQuery('role',ge.role);
gr.query();
if(gr.next()) {
return 'yes';
}
}
return 'no';
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2021 02:56 AM
how do i make sure the user has two roles exactly?
Would appreciate if you could help on this one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2021 03:07 AM
for exact 2 roles you can query sys_user_has_role table with the logged in user and get the row count from query
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader