How to hide annotation using client script for scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 06:19 AM
Hi Team,
I was trying to hide annotation for specific related service. However, it is not working. Please suggest. Related services is a reference field. Isolate script is false and UI type = "All"
//onload client scipt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 06:24 AM
this should work fine -> you should get the HTML ID
function onLoad() {
//onload client scipt
var rel_services = g_form.getValue('related_service').toString();
if (rel_services == "67a3e8301b8c62d00b9a11739b4bcba2") {
document.getElementById('info1').style.display = ''; // show
} else {
document.getElementById('info1').style.display = 'none'; // hide
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 06:30 AM - edited 05-02-2025 06:47 AM
Hi @Ankur Bawiskar ,
I am not getting alert only.it is coming empty and not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 06:52 AM
I hope field related_service is on form and is reference type
the logic I shared should work fine provided the field is present on form, sysId you are comparing is correct and Isolate script is false
function onLoad() {
//onload client scipt
var rel_services = g_form.getValue('related_service').toString();
alert(rel_services);
if (rel_services == "67a3e8301b8c62d00b9a11739b4bcba2") {
alert('inside if');
document.getElementById('info1').style.display = ''; // show
} else {
alert('inside else');
document.getElementById('info1').style.display = 'none'; // hide
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2025 09:50 PM - edited 05-04-2025 09:51 PM
@Ankur Bawiskar this hide annotation script is getting called before the related_services populates on form. hence it is going to else block. I changed the script order but the issue is still the same. Any suggestions here?