The CreatorCon Call for Content is officially open! Get started here.

How to display name instead of user ID for updated by in e-mail notifications

jas101
Tera Expert

Hi all,

 

Please see below for our 'Incident Escalated' e-mail, specifically the 'What will it contain' notification details:

 

* * *

<font face="Calibri">

 

The following incident has been set to escalated by ${sys_updated_by}:

 

Customer: ${caller_id}

Updated: ${sys_updated_on}

Priority: ${priority}

Assignment group: ${assignment_group}

Assigned to: ${assigned_to}

 

Click here to view the incident: ${URI_REF}

* * *

 

We just want to change this part: The following incident has been set to escalated by ${sys_updated_by}: so instead of showing the user ID of who last updated the record, it shows the name of who last updated it. We have tried dot walking using ${sys_updated_by.name}: but this is not working. I have since realised this is because it is not a reference field back to the sys_user table.

 

I understand this should be relatively simple so any assistance would be much appreciated.

 

Many thanks,

D

1 ACCEPTED SOLUTION

Hi dasi,



I put in my reply that the script would return the UserID.



It depends what you want to display. If you want the name, you need to do a little more scripting, and use the mail script as proposed by Sanjeev Kumar above, edited to suit your needs. I've added comments in Blue.



  1. <mail_script>  
  2. var userid = current.sys_updated_by;       // Gets the User ID
  3. var gr = new GlideRecord('sys_user');   // Creates new GlideRecord Object
  4.       gr.addQuery('user_name', userid);     // Queries the table for the record of our user found in line 2
  5.       gr.query();  
  6.       if (gr.next()) {                                                                       // If it finds one....
  7.           var userName = gr.name;                           // set the variable "username" as the users name.
  8.         }  
  9.  
  10. template.print("Updated By: "+userName);   // Print the text "Updated By:" and then the username variable from line 7.
  11. </mail_script>  


Best to remove the comments before adding to your email. This has been tested and works fine on my instance.


View solution in original post

27 REPLIES 27

Sanjeev Kumar1
Kilo Sage

Hi,


In your notification you need to write some email script like.




<mail_script>


var userid = current.updated_by;


var gr = new GlideRecord('sys_user');


      gr.addQuery('user_name', userid);


      gr.query();


      if (gr.next()) {


          var userName = gr.name;


        }



template.print("Updated By: "+userName);


</mail_script>


ryan86
Kilo Expert

Simply put in your email:



<mail_script> template.print(current.sys_updated_by.getDisplayValue())</mail_script>



That returns the UserID of whoever updated the record last I believe.


Ryan VN



That is it, "Keep it simple, stupid" 🙂



http://en.wikipedia.org/wiki/KISS_principle



[]'s


Andre Moreira


Thanks for all the input guys however trying to use this most simple method and testing it in a notification, it is still the user ID and not name that is being 'printed' on the e-mail. Did I need to do anything else prior to adding:




<mail_script> template.print(current.sys_updated_by.getDisplayValue())</mail_script>



to the notification? Thanks again, Daniel


Hi dasi,



I put in my reply that the script would return the UserID.



It depends what you want to display. If you want the name, you need to do a little more scripting, and use the mail script as proposed by Sanjeev Kumar above, edited to suit your needs. I've added comments in Blue.



  1. <mail_script>  
  2. var userid = current.sys_updated_by;       // Gets the User ID
  3. var gr = new GlideRecord('sys_user');   // Creates new GlideRecord Object
  4.       gr.addQuery('user_name', userid);     // Queries the table for the record of our user found in line 2
  5.       gr.query();  
  6.       if (gr.next()) {                                                                       // If it finds one....
  7.           var userName = gr.name;                           // set the variable "username" as the users name.
  8.         }  
  9.  
  10. template.print("Updated By: "+userName);   // Print the text "Updated By:" and then the username variable from line 7.
  11. </mail_script>  


Best to remove the comments before adding to your email. This has been tested and works fine on my instance.