how to write a client script to hide channel field when assignment group is empty on incident

jai281997
Tera Contributor
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jai281997 

you can use onLoad client script for this something like this

function onLoad() {
    // Show contact_type field based on assignment_group value
    var group = g_form.getValue('assignment_group');
    g_form.setVisible('contact_type', group != '');
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

BrianProvencher
Giga Guru

You can accomplish this through a UI policy. Something similar to this: set up your filter like this:

BrianProvencher_0-1746105966818.png

 

Then create a UI action and set it up like this:

BrianProvencher_1-1746106004561.png

 

Hope that helps!

 

 

@jai281997  correction: the UI action should look like this:

 

BrianProvencher_2-1746106110701.png

 

J Siva
Tera Sage

Hi @jai281997 

You can use UI policy to hide the form fields.PFB.

Screenshot_20250501-190011.png

If you still want to use client script, then use below client script (on load/on change)

 

function onLoad() {

    //Type appropriate comment here, and begin script below

    var group = g_form.getValue('assignment_group');

    if (group == '') {

        g_form.setVisible('contact_type', false);

    } else {

        g_form.setVisible('contact_type', true);

    }

 

}

Regards,

Siva

 

Ankur Bawiskar
Tera Patron
Tera Patron

@jai281997 

you can use onLoad client script for this something like this

function onLoad() {
    // Show contact_type field based on assignment_group value
    var group = g_form.getValue('assignment_group');
    g_form.setVisible('contact_type', group != '');
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader