Picking Custom Email Templates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2017 02:39 AM
We have had a need to allow users to compose new emails based on a template and data from the record, which they can then modify and/or verify before sending.
I've looked at a number of options for how to achieve this:
While notifications allow an email to be templated and use values from the record, there are a few shortcomings:
- The user can only specify plain content by e.g. providing a public note.
- The user cannot specify the recipient(s).
- The user cannot provide attachments.
The email client can use templates that are conditional on the values on the record but this means the user has to change a value, save the record then launch the email client to pick a template. There are variations in the community by using mail scripts which can adapt based on a custom URL but that means a) whoever creates the templates needs to understand scripting b) a lot of duplication across the To, CC etc. fields.
Quick messages (starting in Jakarta?) don't support getting values from the record so aren't useful for templating.
In the end I've come up with a new solution, building on existing approaches but utilising the power of the Client Template system.
This post describes how to create a dialog window that will allow the user to pick from a list of available templates and launch the email client with that template.
Note: by default conditions and order fields Client Templates are hidden. Customise the form layout to show these fields and apply conditions / order to only show the templates you want.
What makes this work is a query business rule on the client templates table, which filters the results based on a URL parameter. I've actually built this in a custom app but you can't apply a query business rule from a scoped application so that had to go outside the app ...
Business Rule
Field | Value |
---|---|
Name | Filter by URL parameter |
Table | sys_email_client_template |
Advanced | checked |
Insert | unchecked |
Update | unchecked |
Query | checked |
Script |
|
UI Action
Field | Value |
---|---|
Name | Compose Email |
Table | sc_req_item (** or whatever task table) |
Form button | checked |
Client | checked |
Onclick | composeEmailDialog() |
Condition | gs.hasRole('itil') && current.canWrite() |
Script |
|
UI Page
Field | Value |
---|---|
Name | email_template_picker |
HTML |
|
Client script |
|
Script Include
Field | Value |
---|---|
Name | CustomEmailTemplate |
Script |
|
Client callable | unchecked |
On Requested Items this should provide a new UI Action called "Compose Email". If you have more than one template defined, clicking this will launch a dialog that allows the user to pick a template to compose using. If only one template is defined the user will be launched straight into that template.
- Labels:
-
Scripting and Coding
- 4,726 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2018 12:15 PM
Great work.
For some reason, i'm unable to use the "sys_email_client_template" parameter.
I've got 2 templates (test and test2) on the same table (sc_task), and no matter what value I'm setting in the sys_email_client_template I always get the same random template (test2 in my case).
For example, that URL doesn't work and I'm always getting the test2 template, with or without the parameter:
https://MY_INSTANCE.service-now.com/email_client.do?sysparm_table=sc_task&sysparm_sys_id=f510a3b4db068bc0d982a3e84b9619e4&sysparm_target=sc_task&sys_target=sc_task&sys_uniqueValue=f510a3b4db068bc0d982a3e84b9619e4&sys_row=0&sysparm_encoded_record=&sys_email_client_template=test&sysparm_domain_restore=false&sysparm_stack=no
I also tried to put the template sys id instead of the template name but still without luck.
Any thoughts?
Thank you
Avi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-12-2018 02:24 AM
Hi,
Can you confirm the business rule is working as expected?
Navigate to sys_email_client_template.LIST and add to the URL:
...&sys_email_client_template=test
You should only see the template listed with the name of "test".
Do you have any conditions on the templates?
The only code that should affect the email client is the business rule. Are the other scripts working for you i.e. you get a "Compose Email" button which provides you a choice of templates?
(One last, untested, suggestion - you can disable the email client via a system property - would this have an effect?)
All the best,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 12:04 PM
Great work, I was looking for this.
however it did not work completely, I had to fiddle the ui-page a litte. (change line 5 and 7 to the following values.) because it gave errors
<g:evaluate var="jvar_table" expression="RP.getWindowProperties().get('sysparm_table')" />
<g:evaluate var="jvar_sys_id" expression="RP.getWindowProperties().get('sysparm_sys_id')" />