Hide Subtype field if there is no subtype for type.

Alok Gupta5
Tera Guru
Tera Guru

Hello All 

 

Can you please help me on this requirement?

 

I want to hide the subtype field if there is no subtype is present in the sys_choice table related to particular Type.

Regards,
Alok Gupta 

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@Alok Gupta5 

Is subtype dependent on type?

If yes then I don't think you can hide it. You can use onChange on type and see if any choice is available for subtype by querying sys_choice table

If nothing then hide that field.

But why would there be no subtype for that type?

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

Yes subtype is dependent on type and we have many types where we don't have subtype value. so if subtype is not present why we can show the field its better to hide.

Hello @Ankur Bawiskar , 

 

Can you please give me the script?

 

Regards,
Alok Gupta

@Alok Gupta5 

If subtype doesn't exist for type then hide it

You know which type doesn't have sub-types simply have onChange on type and check the value and hide it

something like this but please enhance

function onChange(control, oldValue, newValue, isLoading) {
        if (isLoading || newValue === '') {
            return;
        }

        if (newValue == 'ABC' || newValue == 'DEF') {
            g_form.setDisplay('subtype', false);
        } else {
            g_form.setDisplay('subtype', true);
        }
    }

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