Trigger an impersonation start event

Community Alums
Not applicable
Can we trigger an impersonation start event when a particular group user is impersonated?
17 REPLIES 17

You can set up your own, custom, policy to do that.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

bitzalini6
Tera Contributor

Hi Lexa, here`s a example of a function that can start and event when a user is impersonated, let me know if you need further help or mark my answer as helpful if it fits your needs:

(function() {
var userEmail = 'user@example.com'; // Replace with the email you want to query
var userGr = new GlideRecord('sys_user');
userGr.addQuery('email', userEmail);
userGr.query();

if (userGr.next()) {
var userSysId = userGr.sys_id.toString();
var imp = new GlideImpersonate();

if (imp.isImpersonating()) {
var currentUserSysId = gs.getUserID();

if (currentUserSysId === userSysId) {
gs.info('User with email ' + userEmail + ' is currently impersonated. Triggering action...');
// Add your custom action here
}

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

whenever you impersonate there is an event logged here

You can have logic on that table and determine who impersonated which user

Parm1 - user who initiated the impersonation

Parm2- user impersonated by Parm1 user

AnkurBawiskar_0-1739441969865.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Community Alums 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Community Alums
Not applicable

Hello Ankur,

I applied After insert business rule on sysevent table but it not responding anything.

Also I created flow on sysevent table to trigger notification But it not responding anything.

Can you please help me?