Script Action fliter to restrict system to impersonate

bhaavani
Tera Contributor

Hi Experts,

 

We have a scenario where there will triggering an email when ever a user perform impersonation. We have a Script Action for this which triggers a notification via an Event. The issue is the email notification is getting triggered as "Your account has been impersonated by undefined". For this we have logged a HI Case and got the solution that we need to include a line in Script action like 
if the user starting the impersonation is “system”, then skip the notification". 

 

The above solution will prevent any Impersonation Email Notifications from being sent out when they are system generated events.   Impersonation events triggered by real users, will still trigger the notifications!

 

Can someone please help me how to trigger/add that line of query in script action as I am new.

 

Thanks in Advance

1 REPLY 1

DpkSharma
Giga Expert

Hi @bhaavani 

To add the condition in the script action to skip the notification if the user starting the impersonation is "system", you can follow these steps:

  1. Navigate to the Script Action record in ServiceNow.
  2. Open the record and locate the "Script" field.
  3. Edit the script and add the following condition before the code that triggers the notification:

 

if (gs.getUserName() === 'system') {
  // Skip the notification for system-generated events
  return;
}

 

Save the script action record.

By adding this condition, the script action will check if the user starting the impersonation is "system". If it is, the script will skip the notification and return without triggering the email.

Please mark my response Helpful and Accepted Solution as applicable!

Thanks & Regards

Deepak Sharma