Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Adding the callers phone number to a link to call on click

Moedeb
Tera Guru

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?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Moedeb 

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

find_real_file.png

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

find_real_file.png

Regards
Ankur

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

View solution in original post

16 REPLIES 16

Sorry, that just tells me how to make a tel link, which I already know. I want it to dynamically pick up the number of the user in the caller field

Ankur Bawiskar
Tera Patron

@Moedeb 

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

find_real_file.png

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

find_real_file.png

Regards
Ankur

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

Worked great thanks @Ankur Bawiskar , I guess the only thing that would be better would be if it went directly to the number and not just show the link to then be clicked on again. ie: Click the phone icon button and the number is called (so the button is the link)