Impersonation in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 10:56 AM
Hi,
Is there a way to impersonate a user through script in scoped application.
I tried impersonating using both the apis gs.getSession().impersonate and GlideImpersonate but getting error as these functions work only in global scope.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 08:11 AM
We have a very good workaround for this which is Run as . You can write a script and set run as the user who you want to impersonate so that the script will run from that user itself. Does it help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 08:29 AM
Hi @deepak50
Let's try this approach.
1. Create a Script Include in the Global.
Sample below
var ImpersonateUtils = Class.create();
ImpersonateUtils.prototype = {
initialize: function() {},
impersonateUser: function(user_id) {
var impUser = new GlideImpersonate();
impUser.impersonate(user_id);
},
type: 'ImpersonateUtils'
};
2. Call the function in the scoped app.
Sample below
var userID = '8e605da4d7700200e5982cf65e610355'; //Robert Turner
new global.ImpersonateUtils().impersonateUser(userID);
gs.info(gs.getUserDisplayName());
Enjoy the result.
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 08:36 AM
Hi @Tai Vu
I have tried this solution, and it works; however, I prefer an alternative approach that doesn't involve relying on any global scripts.
Regards
Varshini