Splitting Multiline

goochg79
Kilo Explorer

Hi,

We have a multiline field on a item which we need to split into the indvidual lines and process these in a JS Script.

Is it possible to convert the multiline into an array, we have tried lines.split ('\n'); and also using match but neither have worked.

1 ACCEPTED SOLUTION

poyntzj
Kilo Sage

I use this in a recent bit of code.   reads a multiline variable.



strUserList = srigr.variables.user_list.toString();


arrUsers=strUserList.match(/[^\r\n]+/g);


View solution in original post

8 REPLIES 8

First convert your variable into a string by changing the first line:



var mylines = '' + current.variables.myLines;



This should work. I tested it out in my instance and it was failing to do anything until this was converted to a string.


poyntzj
Kilo Sage

I use this in a recent bit of code.   reads a multiline variable.



strUserList = srigr.variables.user_list.toString();


arrUsers=strUserList.match(/[^\r\n]+/g);


Julian that is perfect, I hadn't passed the field toString(); which is why this had failed in the past.


Thanks for your help you are a life saver.


Mike Moody
Kilo Guru

Keep in mind that sometimes toString() is not an available function, depending on the object type. In these cases you'll either want to use Stacey's suggestion of var mylines = '' + current.variables.myLines; or a direct string conversion with var mylines = String(current.variables.myLines); - Personally I like to use the latter one whenever I want to reliably get a string.



Mike