- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2017 07:07 AM
Hi ServiceNow community
When inside an incident and putting this command in the browser console g_form.getReference('caller_id').name it works and returns the name of the caller.
When I use the exact same command in a template it does not work and returns a NULL value.
I tested if scripts actualy work in templates by using gs.getUserDisplayName() and this returns the currently logged on user.
What I am trying to do is write more personal messages that Service Desk can use for people that log incidents:
"""
Hi *caller_id_DisplayName*
*customized message which can be anything*
with kind regards
*currently logged on user*
"""
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2017 06:25 AM
Hi Julio,
I don't think Templates were meant to be used in this way. As such, I don't have a solution for your to make the messages parametric. That being said, you might consider an alternative... Create a new table that contains your messages with optional parameters that you control (e.g. ${user_name} or {$caller_id}) and then place a field (for only your properly roled users to see) so they can pick which quick message they want to use. A client script can then do a GlideAjax call to the server, passing the value of this "quick message" field and the server can do the search/replace on the parameters you put in the message, returns the resulting text, and places it in the comments box. This makes it quick to update the messages going forward - in production if desired.
If you want some demonstrations how to use GlideAjax, take a look at episodes 5, 6 and 33 of TechNow.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2017 07:13 AM
Hi Julio,
The template is applied on the server side, which means g_form is not available - that's a client side object.
Can you explain what exactly your requirement is? If you're using a reference field, then a value for caller (for example on incident) could be
javascript:gs.getUserID();
If you want just the name, then
javascript:gs.getUserDisplayName()
as you suggested.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2017 07:18 AM
javascript:gs.getUserDisplayName() get's the displayName from the currently logged on user. We need the Displayname from the "Caller" of the incident.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2017 07:36 AM
Can you provide some details around the use case? I don't know that a template will be the right solution for you in this case, but I'd like to hear more about what you are trying to do. Step by step instructions would be helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2017 07:46 AM
I will make use of an example ticket to try and explain the usage of the template.
1. A ticket comes in ServiceNow asking for access to a drive from user with Displayname: John Doe --> the variable I need to get
2. A Service Desk Employee assigns the ticket to himself and gives access to the specified drive.
3. The Service Desk employee now wants to comment:
"""
Hi John Doe
I have given you permissions on the drive. Please log out and log back in to get access.
With kind regards
Name_Of_Service_Desk_Employee
"""
3.1 Typing the message is a stupid task ServiceDesk employees have to do. We want to make the messages more personal by including the name(Hi, Name_of_Caller) in the comment instead of just "Hi,"
This is what I have now:
"""
javascript:var text ="Hi ";text += gs.getUserDisplayName();text += "\n\nThis is a text message I can fully customize.\n\nwith kind regards\n\n";text += gs.getUserDisplayName();
text;
"""
This displays:
"""
Hi Julio Sanchez-Tirado
This is a text message I can fully customize
with kind regards
Julio Sanchez-tirado
"""
gs.getUserDisplayName() --> currently logged on user in Service now.
The first gs.getUserDisplayName() needs to return caller Displayname of ticket. (in this case John Doe)
The second gs.getUserDisplayName() needs to return the currently logged on user in ServiceNow (in this case Julio Sanchez-Tirado
3.2 In the template the satus get's also changed to closed completed / resolved. (this works)
4. Click on save and ticket is done
Do you have enough information?