Grant Admin Access Via Script

Sadhana
Giga Contributor

Hi All,

We have a catalog process where one can request for Admin access for a given window. This is generally used by our support teams to manage releases and issues on Production.

It was working fine but now it has stopped working after the version upgrade.

Here is the script that I am using, earlier this was in the workflow run script activity, i changed it to a script include and still it did not work, Now I changed this to a script action but it is still not working.

I am getting all the logs.

**************************************************

var usr = event.parm1;
gs.log('usr= '+usr);
//session.onlineImpersonate("admin");
var adminRole = '';
var roleGR = new GlideRecord('sys_user_role');
roleGR.addQuery('name', 'admin');
roleGR.query();
if (roleGR.next()) {
gs.log('2');
adminRole = roleGR.sys_id;
}
gs.log('adminRole= '+adminRole);
var grUserRoleGR = new GlideRecord("sys_user_has_role");
grUserRoleGR.intialize();
grUserRoleGR.user = usr;
grUserRoleGR.role = '' + adminRole;
grUserRoleGR.state = 'active';
grUserRoleGR.inherits = true;
gs.log('3');
grUserRoleGR.insert();

***********************************************

I think the issue is that now to give admin access one should have admin themselves, how to get past this?

15 REPLIES 15

can you please let me know what is the exact requirement ? why are you using script action here ? 

 

i am assuming you want to grant the admin role to the user , if yes then how are you getting the user value ? is there any variable or field which hold the user value ? 

We have a catalog process where one can request for Admin access for a given window. This is generally used by our support teams to manage releases and issues on Production.

It was working fine but now it has stopped working after the version upgrade.

Here is the script that I am using, earlier this was in the workflow run script activity, i changed it to a script include and still it did not work, Now I changed this to a script action but it is still not working.

 

I am passing the user to which admin role should be given form the workflow script where i have triggered the event, as parm 1. I have logged that value too and it is logging correctly.

it should work from workflow as well. 

if something has stopped working after upgrade, did you check any ACL preventing it ?

 

did you add logs to validate the insert() , what exactly its returning in log ?

using workflow it should work. 

Swadesh Saraf2
Kilo Guru

Can you please check this URL, it provides a way to schedule a script and it runs as system administrator.

http://www.john-james-andersen.com/blog/service-now/call-a-servicenow-script-asynchronously-with-sch...

Not clear on how to pass parameters to trigger scheduled job.