Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get event name and parm1 value in email script

jitusingh
Tera Contributor

Hello Everyone,

 

I have an event which contain multiple user sys_ids in parm1. 

 

I want to fetch the event name and parm1 value in email script and covert to array string where parm1 value is list of users which are the recipients.

 

Instance version:- Vancouver

I tried with event.name but event object is not working 

Event name- regulationCoordinators.users

example parm1 value:- 71826bf03710200044e0bfc8bcbe5d3b,0a826bf03710200044e0bfc8bcbe5d7a,a8f98bb0eb32010045e1a5115206fe3a

3 REPLIES 3

karthiknagaramu
Kilo Sage

Hi,

 

You can access vent parameter 1 and 2 in script. Below link will help

https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/notification...

 

But I am not sure if it is possible to access name. Are you able to use parameter 2 to send event name, if not being used currently?

 

Regards,

Karthik Nagaramu

johnfeist
Mega Sage

Hi Jitu_singh,

 

As previously noted, you can access event.name, event.parm1 and event.parm2.  I wrote a little mail script to test that:

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    var theEvent = event.name;
    var theParm = event.parm1;
    gs.log("Event is " + theEvent + " parm is " + theParm, "jaf");

})(current, template, email, email_action, event);

I set up a simple notification and triggered the event.  When I went to the logs, both the event name and parm1 were correctly displayed.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Community Alums
Not applicable

Hi,

 

Assuming you are triggering a notification using event & have added the mail script ${mail_script:email_script_name} in your Notification "Message HTML" field:

 

You can use the below email script.

 

Email script:

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
 
    var parm1Value = event.parm1;
 
    gs.log("Hello "+event.name); // this will give the event name. I tested this
   
    // Convert parm1 value (comma-separated string) to an array of sys_ids
    var userSysIds = parm1Value.split(',');
 
    // Loop through the sys_ids and fetch user email addresses
    for (var i = 0; i < userSysIds.length; i++) {
        var userSysId = userSysIds[i];
       
        // Get user record
        var userGR = new GlideRecord('sys_user');
        if (userGR.get(userSysId)) {
            email.addAddress('cc',userGR.email);
        }
    }
})(current, template, email, email_action, event);
 
Please let me know if you encounter any issues.
Else, Please mark the answer as helpful.

 

 Sai149_1-1715952654176.png

Sai149_2-1715952684104.png