Split returned variable from choice/select into 2 variables

Ron28
Kilo Sage

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

 

6 REPLIES 6

Snehangshu Sark
Mega Guru

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.

Ron28
Kilo Sage

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