Fetch sys_user name with sys_id contained in an event parm (For email notification body)

GabrielCSSMI
Tera Contributor

I'm creating an email notification with a dynamic body value.

This notification will be triggered by an event contaning a user sys_id within parm1 and email body within parm2.

 

The greetings within the notification are standardised. Only the name needs to be changed. Parm1 is used in order to select the email recipient, I thought I could somehow fetch user data using the sys_id using something like: ${event.parm1.name} - it seems there is no way to extract this information dirrectly within the notification. Is there a way to do this?

1 ACCEPTED SOLUTION

Mallidi Suma
Tera Guru

Hi @GabrielCSSMI ,

 

Create a mail script as below

 

Code:-

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
 
          // Add your code here
 
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',event.parm1);
gr.query();
if(gr.next())
{
template.print("Hi " + gr.name);
}
})(current, template, email, email_action, event);

 

Screenshot 2023-05-18 at 2.37.04 AM.png

Call this mail script from the Message HTML in notification using the below syntax

 

${mail_script:getsendername} // getsendername is my mailscript name.

 

Screenshot 2023-05-18 at 2.39.46 AM.png

 

Result :

 

Screenshot 2023-05-18 at 2.40.07 AM.png

 

Please mark my answer as helpful and accept it as a solution, if it helps !!.

 

Thanks & Regards,

Suma.

View solution in original post

1 REPLY 1

Mallidi Suma
Tera Guru

Hi @GabrielCSSMI ,

 

Create a mail script as below

 

Code:-

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
 
          // Add your code here
 
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',event.parm1);
gr.query();
if(gr.next())
{
template.print("Hi " + gr.name);
}
})(current, template, email, email_action, event);

 

Screenshot 2023-05-18 at 2.37.04 AM.png

Call this mail script from the Message HTML in notification using the below syntax

 

${mail_script:getsendername} // getsendername is my mailscript name.

 

Screenshot 2023-05-18 at 2.39.46 AM.png

 

Result :

 

Screenshot 2023-05-18 at 2.40.07 AM.png

 

Please mark my answer as helpful and accept it as a solution, if it helps !!.

 

Thanks & Regards,

Suma.