Using a Switch case in ServiceNow

Abhishek_Thakur
Mega Sage

We can use a Switch Case in ServiceNow for multiple testing to test the different values against the same field.

 

here is the example code, you can start from here to understand basic knowledge.

var category = g_form.getValue('category');
    switch (category) {
        case "hardware":
            g_form.addInfoMessage("Yes category is Hardware");
            break;
        case "software":
            g_form.addInfoMessage("Yes category is Software");
            break;
        case "network":
            g_form.addInfoMessage("Yes category is Network");
            break;
            default:
            g_form.addErrorMessage("Sorry category is something else");
    }

 

2 REPLIES 2

Allen Andreas
Administrator
Administrator

Hi,

Just checking in to see if you had a question or were you sharing this with others in more of an "article" type concept?

I wasn't sure if you needed any assistance 🙂


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

You are correct, because I am not getting the option in community to post an article so I started from here. If you can help me to find the suitable solution to post an article over the community then it would be great help.