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.

Email script for the updated user not appearing in the notification when the user updates the ticket

phr
Tera Contributor

Hi All,

 

I have a requirement where i need to send the notification to the users who update the incident. We have a email script which is already defined and is fetching the email instead of the name .

reference image :

phr_0-1722522395265.png

 

phr_1-1722522469042.png

 

I did write the email script to fetch the name instead of the email :

phr_2-1722522520794.png

 

But this isn't fetching the name 

phr_3-1722522551574.png

 

phr_4-1722522599155.png

 

How to achieve this?

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @phr 

Please change your email script to the one like below.

 

var usrGr = new GlideRecord("sys_user");
usrGr.addEncodedQuery("user_nameSTARTSWITH" + current.sys_updated_by);
usrGr.query();
if(usrGr._next()){
	template.print(usrGr.getValue('name'));
}

 

Please mark my answer helpful 👍 and accept as a solution ✔️ if it helped.

 

Thanks,
Anvesh

View solution in original post

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@phr In your email script, {$sys_updated_by} is used, which is nothing but the user_name of the user who updated the record (which on your instance is user's email (user email is used as user_name on your instance) hence it is showing the email).

 

Replace 

 

Hi @Sandeep Rajput ,

 

I did write the code as attached in the image "getUpdatedBy" which wasn't working fine.

I modified the code now and is working fine.

 

Thank you

AnveshKumar M
Tera Sage
Tera Sage

Hi @phr 

Please change your email script to the one like below.

 

var usrGr = new GlideRecord("sys_user");
usrGr.addEncodedQuery("user_nameSTARTSWITH" + current.sys_updated_by);
usrGr.query();
if(usrGr._next()){
	template.print(usrGr.getValue('name'));
}

 

Please mark my answer helpful 👍 and accept as a solution ✔️ if it helped.

 

Thanks,
Anvesh

Hi @AnveshKumar M ,

 

The code worked, Thank you.