UI Macro - Open teams and start populating message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 10:12 AM
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>
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 12:13 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 02:05 AM
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;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>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 11:08 AM
Unfortunately I don't have a teams account in order to test / help further.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2020 11:44 AM
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;message=Hi ' + firstName + ', this is regarding ticket: ' + number + ' - ' + short_desc;
var w = getTopWindow();
w.open(url);
}
</script>
</j:jelly>