Jelly script not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Guys, I am trying to hide one of the macro 'add_location' present beside assignment group field when the case state is resolved or closed complete. However I am not able to get this worked. Please suggest. Thanks
<?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_num" value="assign_to_user_${ref}"/>
<g:evaluate var=caseState">
current.getValue('state');
</g:evaluate>
<a id="${jvar_num}" onclick="addLocation('${ref}')">
<img border="0" title="${gs.getMessage("Add Location")}"
</a>
<script>
function Onchange_state(element,original, changed, loading){
var visibility = 'hidden';
if(changed.state == '3' || changed.state =='150') { // case state
e.style.visibility = visibility;
} else {
e.style.visibility = 'visible';
}
}
</script>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @praveeng2,
Here’s the corrected answer in two clear points, followed by a working script:
1. What was wrong
- Tag issues:
<g:evaluate var=caseState">is malformed; it should bevar="caseState".- The
<img>tag is incomplete (missingsrcand closing/>).
- JavaScript issues:
- Variable
eis undefined in your function; you need to target the actual element by ID. - The function parameters don’t match ServiceNow’s onChange convention (
newValue,oldValue,isLoading).
- Variable
2. Correct script
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
<!-- Create a dynamic ID for the link -->
<j:set var="jvar_num" value="assign_to_user_${ref}"/>
<!-- Evaluate the current state -->
<g:evaluate var="caseState">
current.getValue('state');
</g:evaluate>
<!-- Add Location link -->
<a id="${jvar_num}" onclick="addLocation('${ref}')">
<img src="images/icons/add.png" border="0"
title="${gs.getMessage('Add Location')}" />
</a>
<script>
function Onchange_state(newValue, oldValue, isLoading) {
var link = document.getElementById('${jvar_num}');
if (!link) return;
if (newValue == '3' || newValue == '150') {
link.style.visibility = 'hidden';
} else {
link.style.visibility = 'visible';
}
}
</script>
</j:jelly>
This corrected script ensures:
- Proper Jelly syntax.
- A complete <img> tag.
- The visibility logic correctly targets the anchor element by ID.
Thanks & Regards,
Siddhesh Jadhav
Accept and mark helpful if it resolved your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
see this link has working solution, check and enhance for your requirement
this link has working solution'
Hiding a UI Macro based on Field Data
response from ewok
by following 1st link, I updated your script, try that
<?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_num" value="assign_to_user_${ref}" />
<g:evaluate var="caseState" jelly="true">
var state = current.getValue('state');
state;
</g:evaluate>
<j:if test="${caseState != '3' && caseState != '150'}">
<a id="${jvar_num}" onclick="addLocation('${ref}')">
<img border="0" title="${gs.getMessage(' Add Location')}"></img></a>
</j:if>
</j:jelly>
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
