- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2015 08:06 AM
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.
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2015 09:19 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2015 08:12 AM
Hi Gareth,
If it is of journal_type then split('\n\n') will work some times. Could you pls elaborate your requirement
Thanks,
Sunil Safare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2015 08:26 AM
Hi Sunil,
The multiline is a variable on a catalog item.
It has several pieces of information seperated on the lines.
As part of the workflow we need to take this information and act on what is contained in the lines.
So I was planning on taking the variable and spliting this into an array and dealing with each line.
eg;
var mylines = current,variables.myLines;
var lines = mylines.split('\n');
for (var i = 0; i <= lines.length; i++) {
prcoess (lines[i]);
}
eg of myLines is made up of;
- staff; 12
- temps:4
- totalPeople: 16
Does this make sense?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2015 09:01 AM
Hi Gareth,
Try to cast the multiline variable to a String like so, I'm not sure if it will work, but maybe:
var multilineString = String(current.variables.myLines);
var multilineArr = multilineString.split('\n');
// Do your loop
If it doesn't work, maybe log the value of multilineString or myLines and see how the data looks to determine how you can split it up properly.
I hope this helps a little.
Regards,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2015 09:02 AM
Hello Gareth,
Could you please log the value of myLines and post the result?
var mylines = current.variables.myLines;
gs.log("My lines are " + mylines );
Thanks