Grant Admin Access Via Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:06 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:11 AM
try now
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('adminRole= '+adminRole);
var grUserRoleGR = new GlideRecord("sys_user_has_role");
grUserRoleGR.intialize();
grUserRoleGR.user = usr;
grUserRoleGR.role = roleGR.sys_id;
grUserRoleGR.state = 'active';
grUserRoleGR.inherits = true;
gs.log('3');
grUserRoleGR.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:18 AM
Hi,
Just tried this and still no luck.
I dont think there is any issue with the script, it is just that I need to make sure it gets executed as 'ADMIN'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:21 AM
how are you executing your event which you used in script action ?
script action run as system
what is your exact requirement ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:26 AM
How can i change the run as on script action? i dont see it?
event is triggered from the workflow.