- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 11:42 PM
Hi All,
I want to change the below multiple if condition to a switch statement. Please help with that
var targetRecord = new GlideRecord("cmdb_ci_ip_router");
if (targetRecord.get("serial_number", source.u_sn) && (source.u_sn != "")) {
return targetRecord.sys_id.toString();
} else if (targetRecord.get("name", source.u_name) && (source.u_name != "")) {
return targetRecord.sys_id.toString();
} else if (targetRecord.get("ip_address", source.u_mgmtip) && (source.u_mgmtip != "")) {
return targetRecord.sys_id.toString();
} else{
return -1;
}
})(source);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 01:43 AM
Hello Suvetha,
You can write logic like this:
var targetRecord = new GlideRecord("cmdb_ci_ip_router");
switch(true){
case targetRecord.get("serial_number", source.u_sn) && (source.u_sn != ""):
return targetRecord.sys_id.toString();
case targetRecord.get("name", source.u_name) && (source.u_name != ""):
return targetRecord.sys_id.toString();
case targetRecord.get("ip_address", source.u_mgmtip) && (source.u_mgmtip != ""):
return targetRecord.sys_id.toString();
default:
return -1;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 01:43 AM
Hello Suvetha,
You can write logic like this:
var targetRecord = new GlideRecord("cmdb_ci_ip_router");
switch(true){
case targetRecord.get("serial_number", source.u_sn) && (source.u_sn != ""):
return targetRecord.sys_id.toString();
case targetRecord.get("name", source.u_name) && (source.u_name != ""):
return targetRecord.sys_id.toString();
case targetRecord.get("ip_address", source.u_mgmtip) && (source.u_mgmtip != ""):
return targetRecord.sys_id.toString();
default:
return -1;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 02:57 AM
@Prasad Dhumal Thank you so much. It worked