Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Macro open Email Client

Maki
Tera Expert

Hello again,

i need a little help with the email client.

I found some threads like (1 / 2) but i dont get it 100% working. 

I got a column in incident "u_mail" with some choices. Different Email Client Templates with a condition to the u_mail. 
If i choose "Antwortmail" for example, click on the default email button (more Options) the Email Template "Antwortmail" opens. So this is working fine.

find_real_file.png

I copied a macro, but missing is the correct URL (??? in macro) to open the Email Client.

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


   <a href="???" target="_blank" class="btn btn-default icon-mail"></a>


</j:jelly>

Or can i just copy the function from the default E-Mail Button (more options menue) to my button? 

1 ACCEPTED SOLUTION

Hi,

 

Please refer below to fulfill requirement:

------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g2:evaluate>

var table, sys_id;
table = RP.getParameterValue('jvar_ref_table');
sys_id = current.sys_id;


var url1="/email_client.do?sysparm_table=incident&amp;sysparm_sys_id=" + sys_id + "&amp;sysparm_target=incident&amp;sys_target=incident&amp;sys_uniqueValue=" + sys_id + "&amp;incident.u_mail_1=";
</g2:evaluate>

<a href="$[url1]" id="temp_link" target="_blank" class="btn btn-default icon-mail" onclick="test(this)">AA</a>
<input type="hidden" id="url_value" value="$[url1]"/>

<script>
function test(a){
var url = document.getElementById("url_value").value;
a.href=url+g_form.getValue("u_mail_1");
}
</script>

</j:jelly>

--------------------------------------------------------------------

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

View solution in original post

17 REPLIES 17

Ash10Patil
Kilo Guru

Hi, 

You can use URL for email generation as "https://<instance_name>.service-now.com/email_client.do?sysparm_table=<table_name>&sysparm_sys_id=<s..."

 

In macro you will need to fetch current record table name and sys_id.

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

 

 

Sorry i cant open the link.

I almost got it, just one thing is missing: 

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	   <g2:evaluate>

   var table, sys_id;
   table = RP.getParameterValue('jvar_ref_table');
   sys_id = current.sys_id;
   var mail = current.u_mail_1.getDisplayValue(); // Not working
		   
  var url = new GlideURL("email_client.do?sysparm_table=incident&amp;sysparm_sys_id=" + sys_id + "&amp;sysparm_target=incident&amp;sys_target=incident&amp;sys_uniqueValue=" + sys_id + "&amp;sys_row=0&amp;sysparm_encoded_record=&amp;incident.u_mail_1=" + mail + "&amp;sysparm_domain_restore=false&amp;sysparm_stack=no");   


   </g2:evaluate>


   <a href="$[url]" target="_blank" class="btn btn-default icon-mail"></a>


</j:jelly>

the var mail is not working. The code without the var mail is working. But then the mail client template "antwortmail" is always opened (because its in the URL)

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	   <g2:evaluate>

   var table, sys_id, mail;
   table = RP.getParameterValue('jvar_ref_table');
   sys_id = current.sys_id;
		   
  var url = new GlideURL("email_client.do?sysparm_table=incident&amp;sysparm_sys_id=" + sys_id + "&amp;sysparm_target=incident&amp;sys_target=incident&amp;sys_uniqueValue=" + sys_id + "&amp;sys_row=0&amp;sysparm_encoded_record=&amp;incident.u_mail_1=antwortmail&amp;sysparm_domain_restore=false&amp;sysparm_stack=no");   



   </g2:evaluate>


   <a href="$[url]" target="_blank" class="btn btn-default icon-mail"></a>



</j:jelly>

 

I created a column "u_mail_1 " with type choice at the incident table. How can i display the current value for the URL?

Hi,

You can get display value of u_mail_1 by using GlideRecord as below.

 

 var table, sys_id;
   table = RP.getParameterValue('jvar_ref_table');
   sys_id = current.sys_id;

var gr = new GlideRecord('incident');

gr.get('sys_id');

var mail = gr.u_mail_1.getDisplayValue();

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

   <g2:evaluate>

   var table, sys_id, mail;
   table = RP.getParameterValue('jvar_ref_table');
   sys_id = current.sys_id;
   var gr = new GlideRecord('incident');
   gr.get('sys_id');
   var mail = gr.u_mail_1.getDisplayValue();
   
		   
   var url = new GlideURL("email_client.do?sysparm_table=incident&amp;sysparm_sys_id=" + sys_id + "&amp;sysparm_target=incident&amp;sys_target=incident&amp;sys_uniqueValue=" + sys_id + "&amp;sys_row=0&amp;sysparm_encoded_record=&amp;incident.u_mail_1=" + mail + "&amp;sysparm_domain_restore=false&amp;sysparm_stack=no");   

   </g2:evaluate>

   <a href="$[url]" target="_blank" class="btn btn-default icon-mail"></a>

</j:jelly>

This way? But still not working. And in the URL is missing the part "incident.u_mail1="