Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Is it possible to use switch case?

AnkitT
Tera Contributor

Hello Community,

 

I want some use case where I can switch case for implementations.

2 ACCEPTED SOLUTIONS

Abhishek_Thakur
Mega Sage
Mega Sage

Hi @AnkitT ,

 

You can refer this link to know about how to use switch case in ServiceNow.

 

https://www.servicenow.com/community/developer-forum/using-a-switch-case-in-servicenow/td-p/2739803

 

Please accept my solution and mark this helpful if it works for you.

View solution in original post

Abhishek_Thakur
Mega Sage
Mega Sage

Hello @AnkitT ,

 

You can connect with me, if you still face any issues.

View solution in original post

3 REPLIES 3

Abhishek_Thakur
Mega Sage
Mega Sage

Hi @AnkitT ,

 

You can refer this link to know about how to use switch case in ServiceNow.

 

https://www.servicenow.com/community/developer-forum/using-a-switch-case-in-servicenow/td-p/2739803

 

Please accept my solution and mark this helpful if it works for you.

Community Alums
Not applicable

Hi @AnkitT ,

Please refer below code 

var gr = new GlideRecord('incident');
gr.addQuery('sys_id', '46e2fee9a9fe19810049b49dee0daf58');
gr.query();
if(gr.next()){
	gs.print("here = " + gr.incident_state)
	switch(gr.incident_state.toString()){
		case "1":
            gs.print("Yes category is Hardware");
            break;
        case "2":
            gs.print("Yes category is Software");
            break;
        case "3":
            gs.print("Yes category is Network");
            break;
	}
}
    

Result 

SarthakKashyap_0-1714733070152.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Abhishek_Thakur
Mega Sage
Mega Sage

Hello @AnkitT ,

 

You can connect with me, if you still face any issues.