Client Script

ankitaayyad
Kilo Contributor

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.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }

    if (newValue == 'non_compliant') {
        g_form.showRelatedList('Issues');
    } else {
        g_form.hideRelatedList('Issues');
    }
}
6 REPLIES 6

SohamTipnis
Mega Sage

Hi @ankitaayyad,

 

Instead of the client script following the best practice to use UI policy, I would recommend you go for UI Policy where you can select the visibility of Related List based on your selected condition.

 


If you need further modification, then you can use the client script, but if this is your only requirement, then the UI Policy is the go-to option.

 

Let me know what you think!!!

 

If you find my answer useful, please mark it as helpful and correct. ‌‌😊


Regards,
Soham Tipnis
ServiceNow Developer || Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10

Ehab Pilloor
Giga Sage

Hi @ankitaayyad,

 

You can make UI Policy, add condition as Status is non compliant and in UI Policy Related List Action Related List, add your Related List and set Visible as true.

 

No code approach is best practice.

 

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor