Conditional display of UI macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 05:05 AM
I have a UI macro that i need to display conditionally without using DOM manipulation on a form. I have applied an id within the macro but am unable to call it within a script to display only when required. It currently displays atall times.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 09:03 AM
Need a little more info. Where is this UI Macro being used? On a reference field, on a form or someplace else?
Can you post the UI Macro?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 05:10 PM
Its being used on a form
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<table id="element.u_request_task.priority_note_rtask" border="0" background-color="yellow" padding="5px" width="100%">
<tr padding="10px">
<td width="100px"></td>
<td width="250px">
<font size="-5">
<b><font color="red">1 - Immediate</font></b> - above ADFSOC duties, other than operational circuits and Problems
</font>
</td>
</tr>
<tr>
<td></td>
<td>
<font size="-5">
<b><font color="red">2 - Important</font></b> - after ADFSOC duties, complete in less than or equal to 15 working days
</font>
</td>
</tr>
<tr>
<td></td>
<td>
<font size="-5">
<b><font color="red">3 - Routine</font></b> - after ADFSOC duties, complete within less than or equal to 30 working days
</font>
</td>
</tr>
</table>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2015 04:56 AM
I would just wrap the whole thing in an IF tag and I myself would tend towards using a role to show the message or membership of a group. I think role would be easier.
http://wiki.servicenow.com/index.php?title=Jelly_Tags#gsc.tab=0
<?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:if test="$[gs.hasRole('SOMEROLETOCHECKFOR')]">
<table id="element.u_request_task.priority_note_rtask" border="0" background-color="yellow" padding="5px" width="100%">
</table>
</j:if>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2015 12:55 AM
Hi, Robert
You can insert your UI macro into the separate section (use formatters) of the form and then it is easy to hide (or show) the whole section with g_form.setSectionDisplay method:
function hideMacro() {
if(condition_is_true) {
g_form.setSectionDisplay('test_section_name', true);
} else {
g_form.setSectionDisplay('test_section_name', false);
}
}
But it works on Fuji only.
For previous versions of ServiceNow the DOM manipulation always helps
function hideMacro() {
var el = document.getElementById('test_id');
if(condition_is_true) {
el.style.display = 'block';
} else {
el.style.display = 'none';
}
}
All above are for the client scripts, of course...