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 the manager

Sandaru1
Tera Expert

Hi,

I need to check the current requester is a manager or not. how can i do that in a script. my complete logic would be like follow.

current_user = requesting user

requested_for_user = value of "requested for" field of request

if(manager of requested_for_user == current_user )

{

return 'yes'

}

else

{

return 'no'

}

please let me know a correct way to do this.

Thanks

/Sandaru

6 REPLIES 6

Sanjeev Kumar1
Kilo Sage

Hi,



If you query on sys_user table in this table we have a Title section or you can use any other flag (custom )   on this table to identify current user is manager or not.


because it may be manager also has manager


santoshsahoonis
Kilo Guru

If i understand you correctly, you either want to know if the current user is a manager OR the current user is a manager of the requested for?


I would do something like this:



To check if the current user is the manager of the requested for user


if(gs.getUserID() == current.requested_for.manager){


        return 'yes'


else


        return 'no';




To check if the current user is a manager or not:


if(isManager(){


        return 'yes';


} else {


        return 'no';


}



// Better to define this in a script include


function isManager(){


        var usr = new GlideRecord('sys_user');


        usr.addQuery('manager', gs.getUserID());


        usr.query();


        if(usr.query()){


                  return true;


        } else {


                  return false;


        }


}


I don't see any function call gs.getUserId()... Can you please send me a reference


Updated. Its getUserID()