Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to check user is logged in user or user has itil role in "If Activity" of workflow.

vishal jaiswal
Tera Contributor

Scenario: There is a catalog item where a field is "Requested for".

Expected sol: I have to check in workflow that "Requested for" is logged in user OR "Requested for" has Itil role. 

How to achieve this through workflow in "If Activity" ?

 

1 ACCEPTED SOLUTION

akasharora
Mega Expert

Hi Vishal,

 

You can do check using

if( gs.getUserID() == current.variables.requested_for || gs.getUser().getUserByID(current.variables.requested_for).hasRole("itil") )

    return "yes";

else 

   return "no";

 

Thanks,
Akash

View solution in original post

7 REPLIES 7

Ahmmed Ali
Giga Sage
Giga Sage

you can write script in workflow if activity by checking advanced check box:

copy script as 

// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
answer = ifScript();
var requestor = current.variables.requested_for + ""; //verify field name
function ifScript() {
if (requestor == gs.getUserID()) {
return 'yes';
}
var roles = new GlideRecord('sys_user_has_role');
roles.addQuery('user', requestor);
roles.addQuery('role.name', 'itil');
roles.query();
if(roles.next()){
return 'yes';
}
return 'no';
}

 

 

find_real_file.png

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

i tried but not working

Can you share your activity screenshot here? also the workflow is on sc_req_item table?  is workflow struck at if activity or it is always going to else?

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali