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:36 AM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:50 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 08:28 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 05:53 AM
Can you please check this URL, it provides a way to schedule a script and it runs as system administrator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 06:44 AM
Not clear on how to pass parameters to trigger scheduled job.