Call Email client from UI Action

ShaidaC
Tera Guru

Hi,
I have a requirement where I want to call an email client template through a UI Action. I have 2 email client templates on the same table. What I want to do is call one template from the OOB Functionality and the other using a UI Action.
Now the issue is that even after putting the correct sys id in UI Action email popup the button click still opens the older template. Can anyone please help me understand why is this happening
Below is my UI Action and email clinet template configuration

ShaidaC_0-1765537839211.png


ShaidaC_1-1765537861310.png

 

1 ACCEPTED SOLUTION

@ShaidaC 

I believe the script shared by @lauri457 won't help here as your question is different.

As per my earlier response it always picks the 1st created email client template

Did you verify that?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

@ShaidaC 

I believe the script shared by @lauri457 won't help here as your question is different.

As per my earlier response it always picks the 1st created email client template

Did you verify that?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

It's undocumented and there is no way to choose a template with any function from what I see. How the template is chosen is not visible to us as the logic is in the email_client.do page but it works something like this:

 

  1. Open the email_client.do page with url params of the table and sysid
  2. As part of the url is the return string from g_form.serializeChangedAll(); which looks like below for example (stores client side changes in a string). 
'&sys_target=incident&sys_uniqueValue=ff4c21c4735123002728660c4cf6a758&sys_row=0&sysparm_encoded_record=&incident.subcategory=internal+application'​
  • The page now has the persistent state of the record and changes from the client side
  • It compares the information from above to the templates in ascending order of the order column in the table and short circuits on first match.

Knowing this we can just change a value on the form, call the function and set the value back inside an ui action and achieve a different template from this ui action to what you would get from the oob button. 

var temp = g_form.getValue("short_description")
g_form.setValue("short_description", "ui action email template");
emailClientOpenPop("incident");
g_form.setValue("short_description", temp);

Make the ui action template lower order than the one that should trigger from oob button

lauri457_0-1765841518400.png

It's very hacky and I would just recommend using quick messages [sys_email_canned_message]

Ankur Bawiskar
Tera Patron

@ShaidaC 
this KB tells the same i.e. 1 email client template per table can be used

Email client only supports one email client template per table 

Instead of this you can use quick messages

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

That KB article looks like it might be ai hallucination. If there are no matching templates the parameter email_client_template does nothing even if it is passed an existing template on the correct table. If there is a matching template the first match is chosen regardless of what you have in that parameter.