- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 09-10-2015 02:51 PM
Call me strange but when it comes to UI design I think buttons related to fields should be next to the field. In ServiceNow I've been told numerous times that I can either have a Form Button in the banner or a Form link at the bottom - why? Why not next to the field?
Well I set out to find a solution and quite quickly found one using UI Macros - but I am on Fuji with it's new UI and nice monochrome button icons - how can I get that look and feel on my own UI macro?
To create a UI macro with new style icons try the following (if anyone has any reason to believe that there may be unintended consequences then please comment - and - use at your own risk):
My use case here was to add a button next to the Current Contact field to get the contact number of the Caller captured in the Caller field (we don't want to pre-populate it as we want to encourage asking for the current number if possible - people tend to move around a lot):
To build this:
- Add a system UI macro (enter 'ui macros' in the navigation) - give it a useful name e.g. getCallContact
- Create your script - in this case I used the following:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_n" value="getCallContact_${ref}"/>
<a id="${jvar_n}" onclick="getCallContact('${ref}')" title="Get Caller's Contact No." class="icon ref-button icon-phone btn btn-default btn-ref"></a>
<script>
function getCallContact(reference) {
//Get the related reference field ready for populating
var s = reference.split('.');
var referenceField = s[1];
//Get office phone for affected user or mobile if no office phone
//Cycle options if there are any on future clicks
userObject = g_form.getReference('caller'); //Change this if caller is in another field.
var officePhone = userObject.phone;
if (officePhone.length==0 || g_form.getValue(referenceField)==officePhone) {
var mobilePhone = userObject.mobile_phone;
g_form.setValue(referenceField, mobilePhone);
}
else
{
g_form.setValue(referenceField, officePhone);
}
}
</script>
</j:jelly>
- This is the clever bit - you will notice in the code above that I have created the button as an <a> tag - in here I specify the title (for a hover hint) and a class - in the middle of the class there is a reference to the button icon 'icon-phone' - this can be changed to any icon in the ServiceNow css (see my other article)
- Now configure the dictionary of the field you want to apply the button to and add a reference to your script in the attributes field:
ref_contributions=getCallContact
And that's it! Save and reload your form and there you are - beautiful Fuji-style buttons next to your fields - easy to understand and more productive!
Thanks to whoever I got the css trick from (I found something on Google and can't recall it)

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How do you position this button where you want it to?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You add the following line to the dictionary entry for the field you want to add the button after (see the image):
ref_contributions=getCallContact
The order of the attributes entries defines the order of the buttons.
This should give you quite a lot of flexibility but other than this there is no control over placing the button exactly - for that you would need to write a custom UI page.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Paul Jackson,
I want to add the phone icon or my custom image next to the contact field in the case form.
Is it possible?
As i'm new to the jelly script, example scripts are appreciated.
Thanks in advance!!!
Regards,
Sensiple
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Fantastic article Paul!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Paul,
is there a way to make it a hover button instead of a click button? Requirement is for users to hover over the icon to get the Impact Help.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I don't believe so - the hover you are referring to is generated by the platform for reference fields and the pop-up contains the sys_popup view for the record referred to in the field.
You may be better off using hints for this sort of thing or I see that in Istanbul you can leverage the overview help panel to provide context sensitive help.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Zachary,
You could always add a url onto the Label for the Impact field and when clicked have that direct to a KB article that explains the impact field. To do this:
1.Create a KB article explaining all about Impact and publish it.
2. View the article and click Copy Permalink at the bottom of the KB article
3. Right Click on the Impact field and choose Configure Dictionary
4. On the Labels Related List select the correct entry for the Label for the table you are on
5. Click the Unlock icon on the URL field and paste in the Permalink of the KB article you created in step 1. Relock the URL field and save the Field label record.
Once done your Impact filed will look like this:
and if the user clicks on the 'Impact ?' label it will open a tab in your browser where they will be taken to your KB Article explaining all about Impact
Not quite as nice as the hover functionality you wanted, but works a treat.
Regards,
Paul.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
A nice solution and as Paul C says probably about as close as you are going to get to what you want, without doing custom UI work.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Zachary,
You can easily do what you what by using css rule.
Here is just a fast example using parent element with id view_test , all content inside popup div and css rules defined in <style> tag
<style>
#view_test div.popup{
display:none;
}
#view_test:hover div.popup{
display:block;
}
</style>
Trick is to hide you popup by default with the first rule.
But when you hover a mouse over an element - more specific selector override the visibility rule so hidden content will be shown
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
An interesting solution, although I would recommend extreme caution using non-platform code to achieve the result.
I appreciate that this make me a bit of a hypocrite because I use a custom solution with the <a> tag above but I still think it's worth pointing out that any custom (non-platform) code may not survive upgrades and may stop working without notice.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Well, in case code above is written in custom UI macros like getCallContact from ref_contributions=getCallContact
he only possibility to break i can imagine is dropping support of UI macros. But this UI macros code can be easily migrated to client script then, the only tricky thing will be add your custom elements ad style after page is loaded.
Hiding element implementation is a part of CSS standard so i believe is the thing that could not be broken.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
My requirement is that when we hover over the phone icon and the user has multiple numbers, then those numbers will be displayed on hover and then the number the user selects, the call is placed to that number. Can you help me how to achieve this. Any help is appreciated (I am new to macros. still learning)
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Zachary,
Can you plz suggest me how did u achieved your functionality?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How can we add UI Macro mutton beside the custome varialble, i don't see any dictionary for variables.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
I've used your tips and it's work almost well... just a question about how to "place" the button next to the field in that case?
Thanks for your help 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello eddy42,
I have an requirement, the question mark icon should be next to the field as shown in the image, and it is a non-reference field. Can anybody help me with this. I have tried with client script but I'm unable to get as my requirement.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
can u please help me with this

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Looks like you just need to fill Hint field for label:
right click on that field> configure label> enter your message in hint field