- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 09:10 PM
Hi.
In my project, Incident Description(String Type) is described as below.
Table: incident
Summary: testData(2022/08/10 13:00:00)
FirstDate: 2022-08-02 13:00:00
LastDate: 2022-08-10 13:00:00
ID: XX1 TEST_20220810_1234_33
Desc: テスト起票
Group: Help Desk
The left is the item and the right is the value, but is it possible to make only the right an array?
If possible, please tell me how to do that.
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 10:00 PM
Please use below script
var t="Table: incident\nSummary: testData(2022/08/10 13:00:00)\nFirstDate: 2022-08-02 13:00:00\nLastDate: 2022-08-10 13:00:00\nID: XX1 TEST_20220810_1234_33\nDesc: テスト起票\nGroup: Help Desk";
//above variable is just to get the value from description field here I used a test string
var tt=t.split("\n");
var fArr=[];
for(var i=0;i<tt.length;i++)
{
fArr.push(tt[i].split(": ")[1])
}
gs.info(fArr)
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 10:00 PM
Please use below script
var t="Table: incident\nSummary: testData(2022/08/10 13:00:00)\nFirstDate: 2022-08-02 13:00:00\nLastDate: 2022-08-10 13:00:00\nID: XX1 TEST_20220810_1234_33\nDesc: テスト起票\nGroup: Help Desk";
//above variable is just to get the value from description field here I used a test string
var tt=t.split("\n");
var fArr=[];
for(var i=0;i<tt.length;i++)
{
fArr.push(tt[i].split(": ")[1])
}
gs.info(fArr)
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 10:17 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 10:02 PM
Hi @d-aizawa ,
If all you're trying to do is convert a comma separated list of strings to an array, the Javascript .split() method will do that for you without doing anything further.
var strList = 'abcd, efgh, ijkl';
var strArray = strList.split(',');
console.log('list: '+ strList + ' array: ' + strArray);
for (i = 0; i < strArray.length; i++) {
console.log("strArray["+i+"]: " + strArray[i]);
}
This will almost get it done, but since you have spaces embedded in your list, the actual output may not be exactly what you expect. To wit:
node splitExample.js
list: abcd, efgh, ijkl array: abcd, efgh, ijkl
strArray[0]: abcd
strArray[1]: efgh
strArray[2]: ijkl
Now you could trim each string and push it to an array as seen in other examples here, or you could use the .replace() method in conjunction with .split() to remove the spaces in the string prior to parsing like this:
var strList = 'abcd, efgh, ijkl';
var strArray = strList.replace(/ /g,'').split(',');
console.log('list: '+ strList + ' array: ' + strArray);
for (i = 0; i < strArray.length; i++) {
console.log("strArray["+i+"]: " + strArray[i]);
}
And that gives us this output: NOte that the original string is unchanged, but the elements of the array that results are trimmed.
list: abcd, efgh, ijkl array: abcd,efgh,ijkl
strArray[0]: abcd
strArray[1]: efgh
strArray[2]: ijkl
For your reference, I recommend:
https://www.w3schools.com/jsref/jsref_split.asp
https://www.w3schools.com/jsref/jsref_replace.asp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 10:30 PM
Below script will solve your issue:
var disc=current.discription;
var strDisc=disc.split("</br>");
var arr=[];
var val=[];
for(var i=0;i<strDisc.length;i++)
{
val=strDisc[i].split(": ");
arr.push(val[1])
}
gs.info(arr)
Regards, Shekhar