The CreatorCon Call for Content is officially open! Get started here.

Impersonation in scoped application

deepak50
Tera Contributor

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

7 REPLIES 7

Shamma Negi
Kilo Sage
Kilo Sage

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?

Regards,Shamma Negi

Tai Vu
Kilo Patron
Kilo Patron

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.

TaiVu_0-1698679730716.png

 

Let me know if it works for you.

 

Cheers,

Tai Vu

varshinin
Tera Contributor

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