Sergio WWSD
Tera Explorer

Ever wanted to order Email Client Templates in the Workspace?

NOTE: If you just want the solution skip below to the section "The Actual Solution", although you might need to read a bit before to situate yourself.

 

Email Client Templates - Quick Intro

Email Client Templates can be huge time-savers for fulfillers by allowing users to, with just the click of a button, create entire emails with pre-populated recipients, subject and body.

They can even be table specific and auto include record information within like Caller, Subject Person, etc:

Email Client Template exampleEmail Client Template example

Which is replaced with the relevant data from the record you're open the Email Client from:

Email Client Workspace ExampleEmail Client Workspace Example

The Problem

However, despite the Email Client Template records themselves including an Order/Execution Order field, OOTB the display order of said templates in the Configurable Workspace, as seen above on the right, is seemingly random. This can be frustrating when certain templates could be more important/frequent, or if a certain order of emails just makes sense.

 

A colleague of mine brought this to my attention when building a few templates for our internal HR and others seem to have had this issue in the past too, with no resolution or suggestions seemingly available.

I've recently been delving into the UI Builder and Configurable Workspace (CWS) related work, so I thought I'd take a crack at it, and the solution is actually quite simple!

 

Finding the solution

We can see which page we need to check out on the UI Builder via the URL when the email draft subtab opens after clicking on "Compose Email":

URL for the email draftURL for the email draft

The "record page" will have several variants, depending on which workspace you're doing this for:

Record Page Variants in UI BuilderRecord Page Variants in UI Builder

Draft Email is the one we're looking for and when opening it we see the below:

Email Draft Record Page variantEmail Draft Record Page variant

On the left, we can see both the Response and Email Templates containers, with an Agent Assist component in each of them:

Containers and Components we are interested inContainers and Components we are interested in

The process to order the Response Templates is the same as Email Templates, so I'll focus on the latter only. After clicking on the "Agent assist 2" component above, the Config tab opens on the right:

Component ConfigComponent Config

The "Table config" is what we're looking for here. OOTB, the record is "Email Templates [sys_email_draft]. We can find this record by searching for Table Configuration in the Native UI:

Table Configuration module in Native UITable Configuration module in Native UI

Where searching by the name in the Component above we find the relevant record:

Table Configuration record in listTable Configuration record in list

We're interested in the Filter Configurations related list where you will find a single record:

Table Configuration recordTable Configuration record

Filter Configuration recordFilter Configuration record

The script found on the filter is what serves the data up to the component we saw before, and what we need to edit to serve it in an ordered manner.

For this article I modified the existing filter record, which although ServiceNow says you can't do, you actually can if you change your Application to @Servicenow/now-email-client. I did this for 2 reasons:

  • If ServiceNow update the OOTB filter in the future we WANT it to show up on upgrades, so we can assess whether we want the changes or not.
  • This Table Configuration is used across all workspaces, so if you change the OOTB one, it will impact all of them, which we wanted on this development.

However, if you want to avoid heavy customisation on the OOTB script you have 2 options:

  1. Creating your own Table Configuration and Filter Configuration, replicating the OOTB one. You will then need to also duplicate the Page Variant and deactivate the OOTB one, so you can configure the Component Table config option we saw above.
  2. Deactivate the OOTB Filter Configuration record and create your own under the same Table Configuration record. It's still a customisation that will flag up on the updates, but much smaller and has a much smaller footprint than option 1.

I've admittedly only tried option 2 but if you have a go at option 1 do let me know if it worked the same!

 

The Actual Solution

All that's left to do is update the script to include the orderBy function that is always found on GlideRecord:

 

 

(function(current, query_table){
	query_table.addQuery("table", current.sys_class_name);
	query_table.orderBy('order');
	// Return the encoded query
	return query_table.getEncodedQuery();
})(current, query_table);

 

 

I chose to order by the 'order' field, but you can of course use name, updated, created, etc.

If we now navigate to the Workspace, we can see the templates are ordered by 'order':

Ordered Email Client TemplatesOrdered Email Client Templates

Ordered Email Client Templates in WorkspaceOrdered Email Client Templates in Workspace

 

The above was relevant to the HR Agent Workspace (Configurable Workspace), but it should be very similar in all other Workspaces.

 

Thanks for reading! If you have any questions or issues let me know!

Comments
Mikael Routy1
Tera Contributor

Hello,

Thank you for sharing this article, it's quite a good solution that could fit our need.

How did you resolved the fact that the now_email_client app is private ?

We cannot edit any record on our side

MikaelRouty1_0-1754938480415.png

 

Sergio WWSD
Tera Explorer

Hi Mikael,

Glad you found the article useful!

I mentioned in my post that I was able to modify it by manually changing my Application scope to '@Servicenow/now-email-client' from the application picker.

Not sure if this was a quirk of my instance but if you find that yours won't allow it, you should be able to create your own Filter Configuration record and set that one on the 'Email Templates' Table Configuration as the active record.

Hope that helps!

Version history
Last update:
‎02-11-2025 09:10 AM
Updated by:
Contributors