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 to redirect to teams chat window

Tapish Sharma1
Kilo Sage

Hi Folks,

I have a requirement to add a teams link besides a User reference field ('Responsible Leader'). I have written a UI macro but it is not working - Below is the script  (Also open to go with any other approach if possible)

**My script and field both are in Customer service Scope

UI Macro 

<?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><img src ="1batch.png" width = "25%" height = "25%" onClick = "userWindow('$(ref)')" tabindex="0" ></img></a>

<script>
function userWindow(reference){
var refVal = reference.split('.');
var fieldName = refVal[1];
var emailId;

var sysId= g_form.getValue(fieldName);
var user = new GlideRecord('sys_user);
if(user.get(sys_id)){

emailId = user.email.toString();
}

if(emailId){
open('sip:'+emailId, '_top');

}
else{
g_form.addErrorMessage('User Does not have email in servicenow');

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

1 ACCEPTED SOLUTION

Hi,

try this and share the alerts

<?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="userWindow('${ref}');"
	   name="${jvar_n}"
	   onmouseout="lockPopup(event)"
	   tabindex="0"
	   >
		<img border="0" src="1batch.png" width="28" height="28" title="${gs.getMessage('Open Teams chat')}" />
	</a>

	<script>
		function userWindow(reference){
		var refVal = reference.split('.');
		var fieldName = refVal[1];
		var emailId;
		alert('fieldName->' + fieldName);
		var sysId= g_form.getValue(fieldName);
		alert('sysId->' + sysId);
		var user = new GlideRecord('sys_user'); // quote was missing
		if(user.get(sysId)){ // variable name corrected
		emailId = user.email.toString();
		}

		if(emailId){
		open('sip:'+emailId, '_top');
		}
		else{
		g_form.addErrorMessage('User Does not have email in servicenow');
		}
		}
	</script>
</j:jelly>

Regards
Ankur

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

View solution in original post

14 REPLIES 14

Maik Skoddow
Tera Patron
Tera Patron

Hi

I see at least one line with a typo. Instead of

var user = new GlideRecord('sys_user);

write

var user = new GlideRecord('sys_user');

And also include as many as possible log statements to make sure your variables have the expected values.

Kind regards
Maik

Hi Maik ,

I corrected that Thanks , when I was debugging, I added errorMessage for fieldName and sysId , but both are showing empty. 

 

Hi @Tapish Sharma 

I wrote an article and developed a similar macro you can take as a blueprint: https://community.servicenow.com/community?id=community_article&sys_id=e0539ea9db30a010d5c4d9d968961...

Kind regards
Maik

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

any browser console error when that icon is clicked?

update as this; 2 changes in bold

 

<?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><img src ="1batch.png" width = "25%" height = "25%" onClick = "userWindow('$(ref)')" tabindex="0" ></img></a>

    <script>
        function userWindow(reference){
        var refVal = reference.split('.');
        var fieldName = refVal[1];
        var emailId;

        var sysId= g_form.getValue(fieldName);
        var user = new GlideRecord('sys_user'); // quote was missing
        if(user.get(sysId)){ // variable name corrected
        emailId = user.email.toString();
        }

        if(emailId){
        open('sip:'+emailId, '_top');
        }
        else{
        g_form.addErrorMessage('User Does not have email in servicenow');

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

Regards
Ankur

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