Fetch event parameters in mail script

Community Alums
Not applicable

Hello ,

I have case to send the notification to impersonated user of "People solution" group

For this, We created script action , event, notification and mail script.

We are not able to fetch parm1 and parm2 in mail script. We get either of event parameter and not both.

 

Script action-

 

var impersonater = event.parm1;
var impersonate = event.parm2;
//Retrieve the user record for the impersonater variable
var grUSer1 = new GlideRecord("sys_user");
grUSer1.addQuery("user_name", impersonater);
grUSer1.query();
if (grUSer1.next()) {
    var impersonater_user1 = grUSer1.sys_id;
}
//Retrieve the user record for the impersonate variable
var grUSer = new GlideRecord("sys_user");
grUSer.addQuery("user_name", impersonate);
grUSer.query();
if (grUSer.next()) {
    var impersonate_user = grUSer.sys_id;
}
// Check if the impersonator is a member of the specified group
var grUserMemberCheck = new GlideRecord("sys_user_grmember");
grUserMemberCheck.addEncodedQuery('group=955ff733fbe7d250a322f59ff4efdce7'); // The group to check membership for
grUserMemberCheck.addQuery("user", impersonate_user); // Use the impersonate_user variable to check if they're a member
grUserMemberCheck.query();
if (grUserMemberCheck.next()) {
    gs.eventQueue('impersonation.people_support', 'sys_user', impersonater_user1, impersonate_user);

} else {
    gs.log("Impersonator is not a member of the group.");
}
 
Email script-
 gs.log("Event params: " + event.parm1 + " has impersonated " + event.parm2);
 template.print( event.parm1 + ' has impersonated ' + event.parm2);
 
notification- 
${mail_script:Unauthorised_access}
${event.parm1} impersonated ${event.parm2} account.

 

1 ACCEPTED SOLUTION

GopikaP
Mega Sage

Hi @Community Alums , in here - gs.eventQueue('impersonation.people_support''sys_user', impersonater_user1, impersonate_user); instead of that - use 

gs.eventQueue('impersonation.people_support', grUserMemberCheck, impersonater_user1, impersonate_user);

If It's still not working. Please log the values of the 'impersonater' and 'impersonate' variables. 

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

notification is on which table?

How are you configuring the recipient?

this line expects a GlideRecord object of the table on which notification is configured

Event should also be on same table

If your notification, event is on sys_user_grmember table then use this

Also ensure you pass the recipient correctly

gs.eventQueue('impersonation.people_support', grUserMemberCheck , impersonater_user1, impersonate_user);

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.

As per new community feature you can mark multiple responses as correct.

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