How to display created by name instead of user id in notification

sushmachava
Tera Contributor

 

Hi,

I want to display the name of the created by instead of user id, below script dispalying the user id of the record in the email notification. could you please help me

 

Application ${name} created by ${sys_created_by} with MRC Accreditation ${u_mrc_acc}.

 

 
 

 

1 ACCEPTED SOLUTION

Voona Rohila
Kilo Patron
Kilo Patron

Hi @sushmachava 

You need to query the user table with user id details and get the name.

Write a mail script with below logic and include in body of the notification.

  var grSysUser = new GlideRecord('sys_user');
    grSysUser.addEncodedQuery("user_name=" + current.sys_created_by);
    grSysUser.query();
    if (grSysUser.next())
        template.print("Application" + current.name + "created by " + grSysUser.name + " with MRC Accreditation " + current.u_mrc_acc);

 

Scripting for email notifications 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

3 REPLIES 3

Hemanth M1
Giga Sage
Giga Sage

Hi @sushmachava ,

 

Created by is a system created (OOB) string field type and populated when record is inserted to database (i wouldn't recommend to change this logic to display Name instead user id)

 

Can you use Opened by instead >> ${opened_by} which gives Name.

 

Thank you,

Hemanth 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Voona Rohila
Kilo Patron
Kilo Patron

Hi @sushmachava 

You need to query the user table with user id details and get the name.

Write a mail script with below logic and include in body of the notification.

  var grSysUser = new GlideRecord('sys_user');
    grSysUser.addEncodedQuery("user_name=" + current.sys_created_by);
    grSysUser.query();
    if (grSysUser.next())
        template.print("Application" + current.name + "created by " + grSysUser.name + " with MRC Accreditation " + current.u_mrc_acc);

 

Scripting for email notifications 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Thanks Voona