Restrict impersonnate a specific user

aymane
Tera Contributor

Hello,

 

I don't know how to restrict impersonnate for a specific user.

 

I have a user that won't to be impersonnized.

 

Could you help me please with that ?

 

Thanks,

Aymane

2 ACCEPTED SOLUTIONS

Hi @aymane ,

 

Please check the below:

var ImpersonateEvaluator = Class.create();
ImpersonateEvaluator.prototype = {
    initialize: function() {},
    type: 'ImpersonateEvaluator',
    canImpersonate: function(currentUser, impersonatedUser) {

        //Change the sysId as per your requirement

        if (impersonatedUser.getID() == "b9377c460b0131109dae8a8db777b295") {
            return false;
        } else {
            return true;
        }
    }
};

 

Result:

SN_Learn_0-1740997499820.png

 

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

@aymane 

I believe the same solution I shared 29 mins ago to use == and not ===

If my response helped please mark it correct as well so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

aymane
Tera Contributor

Hey @GopikaP 

 

I have aleady done this : 

 

aymane_0-1740994515777.png

 

However, I still can impersonnate this user.

 

Thanks.

Hi @aymane ,Please remove the return 'true' statement in the line 11 and try 

Hi @aymane ,

 

Please check the below:

var ImpersonateEvaluator = Class.create();
ImpersonateEvaluator.prototype = {
    initialize: function() {},
    type: 'ImpersonateEvaluator',
    canImpersonate: function(currentUser, impersonatedUser) {

        //Change the sysId as per your requirement

        if (impersonatedUser.getID() == "b9377c460b0131109dae8a8db777b295") {
            return false;
        } else {
            return true;
        }
    }
};

 

Result:

SN_Learn_0-1740997499820.png

 

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.