- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 06:36 AM
Hello,
On case form, I need to show an icon beside asset field only if the asset is hosted.
I want to do this functionality in UI Macro without using DOM Manipulation.
Any Idea?
Jelly is not my speciality so help will be appreciate!
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2019 10:23 AM
Hello,
I did it in 4 steps :
1- Create UI Macro in order to show or hide an icon if the asset selected on case form is hosted (only when the case form is loaded)
The UI macro API Name is "sn_customerservice_hosted_asset" and the UI Macro name is "hosted_asset" (CSM application)
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
.hide_hosted_asset_flag {
visibility: hidden;
position: absolute;
left: -1000px;
}
.show_hosted_asset_flag {
visibility: visible;
background-position: 50% 7px;
}
</style>
<j:set var="jvar_n" value="macro_show_hide_${ref}"/>
<span id="${jvar_n}" title="Hosted Asset" alt="Hosted asset" class="btn btn-ref btn-default hide_hosted_asset_flag" style="background-image: url('hosted_asset.png');background-repeat: no-repeat;">
</span>
<script>
function showHideMacro(asset) {
// Get the macro
var elementToShowOrHide = 'macro_show_hide_${ref}';
var myMacro = $(elementToShowOrHide);
//Check for asset hosted status
var assetHostedStatus = asset.u_hosted;
if(assetHostedStatus == 'true'){
// Show the Macro
$('${jvar_n}').removeClassName('hide_hosted_asset_flag');
$('${jvar_n}').addClassName('show_hosted_asset_flag');
}
}
</script>
<script>
addLoadEvent( function() {
g_form.getReference('asset', showHideMacro);
});
</script>
</j:jelly>
2- Add the Attribute "reference contrbutor" in asset field
Use the API Name of the UI Macro
ref_contributions=sn_customerservice_hosted_asset;
3- Create an on change client script in order to show or hide an icon if the asset selected on case form is hosted
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (!newValue) {
// Hide the UI Macro
var elementToShowOrHide = 'macro_show_hide_sn_customerservice_case.asset';
var myMacro = $(elementToShowOrHide);
myMacro.style.visibility = "hidden";
myMacro.style.position = "absolute";
myMacro.style.left = "-1000px";
return;
}
g_form.getReference('asset', showHideMacro);
}
function showHideMacro(asset) {
// Get the macro
var elementToShowOrHide = 'macro_show_hide_sn_customerservice_case.asset';
var myMacro = $(elementToShowOrHide);
//Check for asset hosted status
var assetHostedStatus = asset.u_hosted;
if(assetHostedStatus == 'true'){
// Show the macro
myMacro.style.visibility = "visible";
myMacro.style.position = "static";
} else {
// Hide the macro
myMacro.style.visibility = "hidden";
myMacro.style.position = "absolute";
myMacro.style.left = "-1000px";
}
}
4- Create a specific style for asset field when the asset visible in the case list is hosted
Hope that might help someone!
Regards,
Yass

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 07:02 AM
Hi Yass,
Right click on Asset field-- Configure Dictionary -- Inside Attributes you can see something like "ref_contributions". SO inside that you have to give your macro name where your icon information is available
for example in the below screen shot i am including macro (popup_chat) to show skypepop up icon
Regards,
Harish Murikinati
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 01:20 PM
Hi Harish,
Thanks for your answer.
Nevertheless this is the simple part of the answer that I already done!
I need to build the UI macro like this thread : https://community.servicenow.com/community?id=community_question&sys_id=b603477adb10af08fece0b55ca96...
So I need to do the jelly part in UI Macro, but I am not able to do it.
If someone could help me to understand jelly code in ServiceNow that might be great!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2019 07:03 AM
Hi,
go to UI images from left nav; upload your icon there
go to field styles; select the field you want; give proper field name and value
value: javascript: current.assetField == 'hosted'
style:
background-image: url('images/icons/<yourIconName>');
background-repeat: no-repeat;
background-position: 98% 5px;
padding-right: 30px;
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
03-19-2019 02:33 PM
Hi Ankur,
Your solution work great for list, but my requirement is to work on form!
Thanks,
Yass