- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 10:55 AM
I am trying to add a form annotation that displays only if certain field conditions are met. Can anyone point me in the right direction?
Solved! Go to Solution.
- Labels:
-
User Experience and Design

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2018 12:32 PM
Change your client script to run 'onChange' against the 'Business service' field. Then use the script below (adjusting the Business Criticality values to match yours as needed) and you should be good to go.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Get the 'Business service' reference
var bs = new GlideRecord('cmdb_ci_service');
bs.addQuery('sys_id', newValue);
bs.query(showBSAnnotation);
}
function showBSAnnotation(bs) {
if (bs.next()) {
// Show annotation if high business criticality.
if ((bs.busines_criticality == '1 - most critical') || (bs.busines_criticality == '2 - somewhat critical')) {
// Hide the annotation
$('my_annotation').up().show();
}
else {
// Hide the annotation
$('my_annotation').up().hide();
}
}
else {
// Hide the annotation
$('my_annotation').up().hide();
}
}
Please mark this response correct if I've answered your question. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 03:57 PM
This is fairly simple to do with annotations on a standard form. The first thing you need to do is construct your annotation in a specific way...using an HTML annotation with a uniquely-identifiable container element that you can show and hide with your script. Something like this should work...
Here is the annotation text with HTML as shown in the screenshot for easier copying...
<span id="my_annotation">Here is my annotation message text!</span>
Once you've got your annotation set up correctly you can use DOM manipulation in a client script or UI policy script to target the element and show and hide it whenever you want. Generally DOM manipulation is frowned upon because you can't control what ServiceNow does with the HTML of forms in the future, but in this case, the risk is much lower since you control the ID.
Here's an example of a working client script to show and hide the annotation above based on changes to the category value on an incident. If you're on a London ServiceNow release note that you need to un-check the 'Isolate script' checkbox so that your DOM manipulation script can run without issue.
Here's the script above for easy copying...
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Hide annotation if 'category' is 'hardware'. Show otherwise
if (g_form.getValue('category') == 'hardware') {
// Hide the annotation
$('my_annotation').up().hide();
}
else {
// Show the annotation
$('my_annotation').up().show();
}
}
Please mark this response correct if I've answered your question. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 12:41 PM
Other than the fact that I had to add an onLoad script to hide the annotation at form load, This is perfect!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2020 12:08 PM
I tried using this method from within a scoped app, doesn't work. Is there something I need to consider?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2020 01:29 PM
I got this work, apparently scoped apps client scripts do not have the same exposure to certain APIs as global. added a system property and worked easy
https://community.servicenow.com/community?id=community_blog&sys_id=788c66e1dbd0dbc01dcaf3231f961969
Thread is very helpful