(function executeRule(current, previous /*null when async*/ ) { var dept = current.department.name; gs.addErrorMessage("mainString=" + dept); var depSplit = dept.split("\\"); gs.addErrorMessage("depSplit=" + depSplit[1]); var reDepartSpace = depSplit[1].replace(/[^a-zA-Z0-9]/g, ''); gs.addErrorMessage("reDepartSpace=" + reDepartSpace); var gr = new GlideRecord("cmn_location"); if (gr.get("name", reDepartSpace)) { current.location = gr.sys_id; } })(current, previous);
Output:
How to Split with backward slash() in ServiceNow
Working Code Asked question July 24, 2023