Ajay_Chavan
Kilo Sage

Service-Now – Microsoft Teams

 

Follow below steps to integrate Snow with Teams for popup chat :

 

  1. Add team icon image to images. 

 find_real_file.png

find_real_file.png

 

  1. Now we must call UI macros on Caller ID field:

find_real_file.png

Add popup_chat in Caller ID field attribute as shown below:

 find_real_file.png

 

  1. Now create a popup_chat UI macro

 find_real_file.png

 

 find_real_file.png

Now here is the important part which is UI Script:

 

<?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 class="btn-default;" id="${jvar_n}" onclick="invokeChat('${ref}');">

              <img src="teams.png" width="30"  title="Popup Teams" alt="${gs.getMessage('Click to 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 = 'https://teams.microsoft.com/l/chat/0/0?users='+email;

 

var w = getTopWindow();

w.open(url);

}

</script>

</j:jelly>

 

 

 In this code there is Teams Deeplink given by Teams that we must include.

 

https://teams.microsoft.com/l/chat/0/0?users='+email;

 

 That’s all guys you will see Teams Icon on Caller ID field as below:

 find_real_file.png

  

Now whenever you will select the Caller ID and click on Teams icon it will redirect to teams chat for selected user . 

Please like , share, subscribe to this article.

In case of improvements please suggest me in comments.

 

 

Regards,

Ajay Chavan

+91-9769949577

India

 

Comments
shinu
Kilo Contributor

@AjayChavan We have a requirement to post selected incidents notification to MS Teams using IntegrationHub. We already have starter Pack enabled for our Paris Instance.

Could you please help on this ?

Tanuj8
Kilo Contributor

Hi , i am also facing the same issue . The redirection from the servicenow to MS teams is working but it is redirecting to the latest user in the chat and not the correct user

 

dharanikumar
Giga Guru

Hi All,

How can we show the below teams icon or making that UI macro visible to the ITIL users only?

find_real_file.png
Thank you!!

dharanikumar
Giga Guru

Hi All,

How can we open the MS Teams chat window that UI Macro from the UI Action Button please or How can we make the below code work in UI Action please?

<?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 class="btn-default;" id="${jvar_n}" onclick="invokeChat('${ref}');">
<img src="teams.png" width="30" title="Teams Chat" alt="${gs.getMessage('Click to open Teams chat')}" />
</a>
<script>
function invokeChat(reference) {

var prefix = 'msteams:/l/chat/0/0?users=';
var firstname = g_form.getReference('caller_id').first_name;
var user = g_form.getReference('caller_id').email;

var subject = '&amp;amp;message=Hi ' + firstname + ', this is regarding your Incident (' + g_form.getValue('number') + ') ' + g_form.getValue('short_description');

var w = getTopWindow();
var url = prefix + user + subject;
w.open(url);
}

</script></j:jelly>

Thank you!!

Bharath40
Giga Guru

I'm able to open teams chat from ServiceNow for user that I have chat already created but not for any new

user. I get below error. What am I missing herefind_real_file.png

 

keshavsingh
Tera Contributor

I might be bit late on this post, but has same requirement so:

@arnabbhaumik  You can add subject in your code by getting the ticket number and short description of recrd and then pass the same in 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">

<a class="btn-default;" id="${jvar_n}" onclick="userWindow('${ref}');">
<img src="teams.jpg" width="25%" height="25%" title="Teams Chat" alt="${gs.getMessage('Click to open Teams Chat')}"/>
</a>

<script>

function userWindow(reference){


var prefix = 'https://teams.microsoft.com/l/chat/0/0?users=';

var refVal = reference.split('.');
var fieldName = refVal[1];
var emailId;
var fName;
var subject;

var sysId = g_form.getValue(fieldName);

var usr = new GlideRecord('sys_user');
if(usr.get(sysId)){
emailId = usr.email.toString();
fName= usr.first_name.toString();
subject = '&amp;amp;message=Hi ' + fName + ', this is regarding your Case ' + g_form.getValue('number') + ': ' + g_form.getValue('short_description');
//g_form.addInfoMessage(emailId+' '+fName+' '+'Subject: '+subject);

}

if(emailId){
var w = getTopWindow();
var url = prefix + emailId + subject;
w.open(url);
//w.open(url,'_blank');
//open('sip:'+emailId, '_top');
}else{
g_form.addErrorMessage('User's email is empty');
}


}

</script>

</j:jelly>

 

 

Please mark helpful if this fulfills your requirement. 

Manasa27
Tera Explorer

In Teams message is correctly populating to the user. But it is copying to the next chat as well along with the required user chat. Please let me know how to resolve this issue.

Aniko Hegedus
Tera Expert

@Ajay_Chavan , wonderful article, thanks so much for the work!!

Version history
Last update:
‎10-15-2019 12:46 AM
Updated by: