- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 02:21 PM
How to hide a annotation through UI Policy.
or
Is there a field type only to display the label or text. so that I had set visibility through UI Policy
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- 10,793 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2022 02:10 AM
Hi Nirmala,
Annotation may be hidden using DOM manipulation. DOM manipulation is not recommended because it may stop working after ServiceNow is versioned up.
As an example, I've created a form like below with 3 fields each with annotation. The numeric scale on top is used to show or hide annotation. 0 implies show all annotation.
This is the client script used to hide and re-display annotation. Service Portal and UI have different logic and the first "if (window)" is used to determine if this is being called from Service Portal page or UI page.
In the Service Portal page, 'annotation = this.document.getElementsByClassName("help-tag");' is used to get all annotation elements. 'annotation[i]' reference's the ith annotation with i starting from 0. For example, annotation[1] will be the second annotation in the form. ".style.display == 'none'" will hide the annotation while ".style.display = 'initial'" will re-display it.
In the UI page, 'annotation = document.getElementsByClassName("annotation");' is used to get all annotation elements.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var annotation;
if (window) {
// ui logic
if (newValue == 0) { // if 0, show all annotation
annotation = document.getElementsByClassName("annotation");
for (var i = 0; i < 3; i++) {
annotation[i].style.display = 'initial';
}
} else {
annotation = document.getElementsByClassName("annotation");
if (annotation[newValue - 1].style.display == 'none') { // if hidden, re-display annotation
annotation[newValue - 1].style.display = 'initial';
} else {
annotation[newValue - 1].style.display = 'none'; // hide annotation
}
}
} else {
//service portal logic
if (newValue == 0) { // if 0, show all annotation
annotation = this.document.getElementsByClassName("help-tag");
for (var j = 0; j < 3; j++) {
annotation[j].style.display = 'initial';
}
} else {
annotation = this.document.getElementsByClassName("help-tag");
if (annotation[newValue - 1].style.display == 'none') { // if hidden, re-display annotation
annotation[newValue - 1].style.display = 'initial';
} else {
annotation[newValue - 1].style.display = 'none'; // hide annotation
}
}
}
}
As I've mentioned above, this script uses DOM manipulation so "Isolate script" needs to be disabled.
Execution:
A. Service Portal
step 1: initial form. All annotations are displayed
step 2: Hide annotation 2.
B. UI
step 1: initial form. All annotations are displayed
step 2: Hide annotation 2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 02:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 03:01 PM
Thank you for sharing the link.
But do you know how to get the ID of annotation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 03:44 PM
please have a look here

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2022 02:10 AM
Hi Nirmala,
Annotation may be hidden using DOM manipulation. DOM manipulation is not recommended because it may stop working after ServiceNow is versioned up.
As an example, I've created a form like below with 3 fields each with annotation. The numeric scale on top is used to show or hide annotation. 0 implies show all annotation.
This is the client script used to hide and re-display annotation. Service Portal and UI have different logic and the first "if (window)" is used to determine if this is being called from Service Portal page or UI page.
In the Service Portal page, 'annotation = this.document.getElementsByClassName("help-tag");' is used to get all annotation elements. 'annotation[i]' reference's the ith annotation with i starting from 0. For example, annotation[1] will be the second annotation in the form. ".style.display == 'none'" will hide the annotation while ".style.display = 'initial'" will re-display it.
In the UI page, 'annotation = document.getElementsByClassName("annotation");' is used to get all annotation elements.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var annotation;
if (window) {
// ui logic
if (newValue == 0) { // if 0, show all annotation
annotation = document.getElementsByClassName("annotation");
for (var i = 0; i < 3; i++) {
annotation[i].style.display = 'initial';
}
} else {
annotation = document.getElementsByClassName("annotation");
if (annotation[newValue - 1].style.display == 'none') { // if hidden, re-display annotation
annotation[newValue - 1].style.display = 'initial';
} else {
annotation[newValue - 1].style.display = 'none'; // hide annotation
}
}
} else {
//service portal logic
if (newValue == 0) { // if 0, show all annotation
annotation = this.document.getElementsByClassName("help-tag");
for (var j = 0; j < 3; j++) {
annotation[j].style.display = 'initial';
}
} else {
annotation = this.document.getElementsByClassName("help-tag");
if (annotation[newValue - 1].style.display == 'none') { // if hidden, re-display annotation
annotation[newValue - 1].style.display = 'initial';
} else {
annotation[newValue - 1].style.display = 'none'; // hide annotation
}
}
}
}
As I've mentioned above, this script uses DOM manipulation so "Isolate script" needs to be disabled.
Execution:
A. Service Portal
step 1: initial form. All annotations are displayed
step 2: Hide annotation 2.
B. UI
step 1: initial form. All annotations are displayed
step 2: Hide annotation 2.