The CreatorCon Call for Content is officially open! Get started here.

UI Macro - Open teams and start populating message

Sam Ogden
Tera Guru

Hi All,

I've added a UI macro with a Microsoft Teams icon next to our assigned_to field to open a teams chat for that user.  I've been asked if when it opens it could start the chat message with:

'Hi' + assigned_to.first_name + 'this is in regards to ticket' + number + short_description. 

Has anyone achieved this, we are using the desktop teams app.

current ui macro is:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="show_incidents_${jvar_guid}:${ref}"/>
		
	<a id="${jvar_n}"
	   onclick="invokeChat('${ref}');"
	   name="${jvar_n}"
	   onmouseout="lockPopup(event)"
	   tabindex="0"
	>
   <img border="0" src="teams.png" width="28" height="28" title="${gs.getMessage('Open Teams chat')}" />
   </a>
	

<script>
function invokeChat(reference) {
  var s = reference.split('.');
  var tableName = s[0];
  var referenceField = s[1];
  var v = g_form.getValue(referenceField);
  var email;
  var gr = new GlideRecord('sys_user');
  if (gr.get(v)) {
    email = gr.email;
  }
  var url = 'sip:'+email; 
  
//var w = getTopWindow();
//w.open(url);
window.location = url;

	
}
</script>	
</j:jelly>
11 REPLIES 11

Kieran Anson
Kilo Patron

Hey,

Not sure if the sip:  deeplink supports it but if you're able to change this to the full Teams URL you can use info from the deep links documentation on MS DOCS

https://teams.microsoft.com/l/chat/0/0?users=testuser@domain.com&message=message_var_here

Hi Kieran,

Thanks for the above.  If I try adding '&message=' + message' to the end of the sip: deeplink, it opens teams but I get a message saying it can't find the user and opens a new chat without a message.

If I change the deeplink as you suggest I get taken to a webpage asking if I want to switch to desktop app or continue to web app.  If I click to open desktop it navigates to teams but it seems to have lost the user or the message.  I change UI macro to:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="show_incidents_${jvar_guid}:${ref}"/>
		
	<a id="${jvar_n}"
	   onChange="onChange('${ref}');"
	   onclick="invokeChat('${ref}');"
	   name="${jvar_n}"
	   onmouseout="lockPopup(event)"
	   tabindex="0"
	>
   <img border="0" src="teams.png" width="28" height="28" title="${gs.getMessage('Open Teams chat')}" />
   </a>
	

<script>
	
function onChange(element, original, changed, loading) {
	var visibility = 'visible';
	var sysID = g_form.getValue('assigned_to');
	if (!sysID)
		visibility = 'hidden';

	var e = gel('${jvar_n}');
	e.style.visibility= visibility;
}
	
function invokeChat(reference) {
  var firstName = g_form.getReference('assigned_to').first_name;
  var number = g_form.getValue('number');
  var short_desc = g_form.getValue('short_description');
  var s = reference.split('.');
  var tableName = s[0];
  var referenceField = s[1];
  var v = g_form.getValue(referenceField);
  var email;
  var gr = new GlideRecord('sys_user');
  if (gr.get(v)) {
    email = gr.email;
  }
  var prefix = 'https://teams.microsoft.com/l/chat/0/0?'
  var subject = '&amp;amp;message=Hi ' + firstName + ', this is regarding ticket: ' + number + ' - ' + short_desc;
  var url = prefix +email; 
  
var w = getTopWindow();
w.open(url);
window.location = url;

	
}
</script>	
</j:jelly>

Unfortunately I don't have a teams account in order to test / help further.

 

Community Alums
Not applicable

Hi - I don't know if you ever achieved your goal, but I managed to get it to work 


Please mark as helpful if the below is what you needed.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
<j:set var="jvar_n" value="show_incidents_${jvar_guid}:${ref}"/>
		
	<a id="${jvar_n}"
	   onChange="onChange('${ref}');"
	   onclick="invokeChat('${ref}');"
	   name="${jvar_n}"
	   onmouseout="lockPopup(event)"
	   tabindex="0"
	>
   <img border="0" src="teams.png" width="28" height="28" title="${gs.getMessage('Open Teams chat')}" />
   </a>
	

<script>
	
function onChange(element, original, changed, loading) {
	var visibility = 'visible';
	var sysID = g_form.getValue('assigned_to');
	if (!sysID)
		visibility = 'hidden';

	var e = gel('${jvar_n}');
	e.style.visibility= visibility;
}
	
function invokeChat(reference) {
  var number = g_form.getValue('number');
  var short_desc = g_form.getValue('short_description');
  var s = reference.split('.');
  var tableName = s[0];
  var referenceField = s[1];
  var v = g_form.getValue(referenceField);
  var email;
  var gr = new GlideRecord('sys_user');
  if (gr.get(v)) {
    email = gr.email;
	firstName = gr.first_name
  }

  var url = 'msteams:/l/chat/0/0?users=' + email + '&amp;amp;message=Hi ' + firstName + ', this is regarding ticket: ' + number + ' - ' + short_desc; 
  
var w = getTopWindow();
w.open(url);
	
}
</script>	
</j:jelly>