Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Community,
I am trying to hide the issues related list, when status is compliant and when status is non compliant then the issues related liste should be visible.
Below is the script, please review and let me know if there is anything wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ankitaayyad
Your script is almost correct, but there are two critical issues that will cause it to fail or behave unexpectedly in ServiceNow
1. Remove if (isLoading) return; so the script runs when the form loads, hiding the list by default if the record is compliant.
2. Use the correct list table or relationship name (e.g., sn_grc_issue) instead of the UI label 'Issues'.
This version might help you
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue === '') return;
var relatedListName = 'sn_grc_issue'; // Update to your exact related list table name
if (newValue == 'non_compliant') {
g_form.showRelatedList(relatedListName);
} else {
g_form.hideRelatedList(relatedListName);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
hi @ankitaayyad ,
instead of client script you can use Ui policy
1) click on form hearder -> config -> UI policies -> New
2) select trigger condtion
3) save your record , once you save record you can see "Ui policy related list action"
new -> select your related list you can hide and show related list
If this helps, please mark it helpful or accept it as the solution.
Regards,
Tejas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
hi @ankitaayyad ,
Hi,
The isLoading check prevents the onChange script from running when the form is initially loading. If you want the Issues related list to be hidden or shown correctly when the form first opens, you should handle the initial state separately, for example, with an onLoad Client Script using the same condition.
Keep the isLoading check in the onChange script to avoid unnecessary execution during form loading.
If this helps, please mark it helpful or accept it as the solution.
Regards, Tejas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @ankitaayyad ,
Have you tried UI policy to hide related list ?
Check your hiderelatedList syntax like actual value that you are providing in g_form.hideRelatedList('relationship') ;
Add proper relationship name as value in hideRelatedList function . refer above incident task related list hide code . I tried it on onload to hideRelatedList , you can try as per your logic just check relationship name correctly .
code :