
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 09:45 PM
I want to be able to add a link next to the caller field on for example the Incident form, so when someone clicks on it the phone call will auto launch in our softphone.
I have already proven that if I have a link like this:
<a href="tel:5550080148">Call us at 555-008-0148</a>
The softphone will launch and try to call the number given, so what I'm looking for is how to auto populate the current callers phone number into the link eg:
<a href="tel:[current.sys_user.phone]">Call us at 555-008-0148</a>
Ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2020 10:28 PM
you should create UI macro and then associate it to the caller_id field
Steps below:
1) UI Macro
Name- show_phone_link
HTML:
<?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}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}"
onclick="showRelatedList('${ref}'); "
title="${gs.getMessage('Call phone')}" image="images/icons/tasks.gifx" icon="icon-phone"/>
<div id="myDiv"></div>
<script>
function showRelatedList(reference) {
var phone = g_form.getReference('caller_id').phone;
var url = 'tel:' + phone;
var mydiv = document.getElementById("myDiv");
var aTag = document.createElement('a');
aTag.setAttribute('href',url);
aTag.innerText = "Call us at 555-008-0148";
mydiv.appendChild(aTag);
}
</script>
</j:jelly>
2) update the dictionary as below for caller_id field
in the attributes section add this
To call UI Macro:-ref_contributions=show_phone_link
I have used Assigned to Field for example to show the Icon and link:
It shows the Phone icon
When user clicks on it it shows the link
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2020 07:05 PM
I have left the macros overnight and still have the same issue, also have tried it in a different instance and have the same issue.
I have also found another macro that adds a link to Microsoft Teams that adds the button next to the others that are already there, but I certainly lack the understanding to use that to make the telephone button do the same thing.
I'm wondering if the fact each of the macros I'm trying to use have the same variables and are acting in the same form and therefore causing issues with each other? Like I said I really don't understand all of this.
Here is the code I found for the Teams button/link, hoping this helps?
<?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="send_teams_msg${jvar_guid}:${ref}"/>
<a class="ref-button btn btn-default btn-ref" style="padding:5px 6px 7px; visibility:hidden;" id="${jvar_n}" onclick="openLink('${ref}');">
<img border="0" src="Microsoft_Teams_16x16.png" title="${gs.getMessage('Message with Microsoft Teams')}" alt="${gs.getMessage('Message with Microsoft Teams')}" />
</a>
<script>
function onChange_field(element, original, changed, loading) {
var visibility = 'hidden';
if (changed.length > 0)
visibility = 'visible';
var e = gel('${jvar_n}');
e.style.visibility = visibility;
}
function openLink(ref) {
var email = g_form.getReference(ref.split('.')[1]).email;
var url = 'msteams:/l/chat/0/0?users=';
url += email;
url += '$[AMP]topicname=Chat';
window.open(url, "_blank");
}
var a = ['incident', 'change_request', 'problem'];
for (i = 0; i &lt; a.length; i++) {
var h = new GlideEventHandler('onChange_' + a[i] + 'field', onChange_field, '${ref}');
g_event_handlers.push(h);
}
</script>
</j:jelly>
Also I have some screenshots that hopefully show what I'm having as an issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2020 09:53 PM
Hi,
Did you use the caller_id.phone in the script?
var phone = g_form.getReference('caller_id').phone;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2020 10:08 PM
Yes sorry I meant to include my macros script so you can see what I've done:
Assigned 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}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}"
onclick="showRelatedList('${ref}'); "
title="${gs.getMessage('Call phone')}" image="images/icons/tasks.gifx" icon="icon-phone"/>
<div id="myDiv"></div>
<script>
function showRelatedList(reference) {
var phone = g_form.getReference('assigned_to').phone;
var url = 'tel:' + phone;
var mydiv = document.getElementById("myDiv");
var aTag = document.createElement('a');
aTag.setAttribute('href',url);
aTag.innerText = "Click here to call " + phone;
mydiv.appendChild(aTag);
}
</script>
</j:jelly>
Caller ID:
<?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}"/>
<g:reference_decoration id="${jvar_n}" field="${ref}"
onclick="showRelatedList('${ref}'); "
title="${gs.getMessage('Call phone')}" image="images/icons/tasks.gifx" icon="icon-phone"/>
<div id="myDiv"></div>
<script>
function showRelatedList(reference) {
var phone = g_form.getReference('caller_id').phone;
var url = 'tel:' + phone;
var mydiv = document.getElementById("myDiv");
var aTag = document.createElement('a');
aTag.setAttribute('href',url);
aTag.innerText = "Click here to call " + phone;
mydiv.appendChild(aTag);
}
</script>
</j:jelly>
And for the assigned to dictionary entry I have:
ref_contributions=assgn_phone
And for the caller id dictionary entry I have:
ref_contributions=caller_link
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2020 10:19 PM
Hi,
So are you saying it is working fine and picking the phone of 1 user and not for other
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 12:27 AM
Yes.
If there is only one macro being used it always works as expected for the field it's added to.
If it has both fields enable with their respective macros it appears to always pick up the assigned to field, but shows the link up at the caller id field.