Split returned variable from choice/select into 2 variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 10:24 PM
Hello,
In a Standard Catalog item I have added a choice question from a cmdb table. This choice returns the value from 2 columns in the cmdb table, separated by a vertical bar. But they are one single variable, I need to split these 2 values. Where can I do this? In Flow designer?
Thanks
Ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 11:10 PM
Hi Ron,
Use split("<delimiter>") to turn your variable into an array based on the <delimiter>. After that you can loop through all the parts by index - 0,1,2... etc. e.g. ->
var variableName = "change/incident"; // variableName is a string
var newArray = variableName.split("/"); // newArray is an array and "/" is a delimiter
gs.info("value 1: "+newArray[0]);
gs.info("value 2: "+newArray[1]);
Result:
*** Script: value 1: change
*** Script: value 2: incident
Regards,
Snehangshu Sarkar
Please mark an appropriate response as correct if my answer replied to your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 11:32 PM
Thanks everyone, I'm ok on the javascript but didn't know where to put this in Service Now. It'll be on the client side as the values are to be passed to another application.
Thanks again,
Ron