- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 09:02 AM
I have a requirement where I need to parse a string from multiline text.
For example input string could be
Input String will be
"**** Begin bla bla bla- ****
Hello Word please pick me
from the annoying bla
**** End bla bla bla ****"
I need to parse the material in between Begin and End
out put should be
"Hello Word please pick me
from the annoying bla".
need some suggestion to perform this in most efficient way. Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 10:27 AM
Hello @ashu1612
Here is the script to meet your requirement:
var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0010683'); // Query the correct record
gr.query();
if (gr.next()) {
var desc = gr.getValue('description'); // Get the description field value
gs.print("Input string: " + desc);
// Encode the input string
var encodedString = encodeURIComponent(desc);
gs.print("Encoded string: " + encodedString);
var arr = encodedString.split('%0A');
arr.join("");
var arr2 = arr.slice(1,arr.length-1);
gs.print( decodeURIComponent(arr2).replaceAll(',',""));
}
- To test the script I have considered taking input from description a multiline text field from incident table.
- This will work for any number of input lines.
Approach:
- Take the input from multiline text field, encode the entire string.
- %0A is the encoded value for enter, so split the encoded string wrt %0A and then slice the first and the last line.
Result:
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 10:27 AM
Hello @ashu1612
Here is the script to meet your requirement:
var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0010683'); // Query the correct record
gr.query();
if (gr.next()) {
var desc = gr.getValue('description'); // Get the description field value
gs.print("Input string: " + desc);
// Encode the input string
var encodedString = encodeURIComponent(desc);
gs.print("Encoded string: " + encodedString);
var arr = encodedString.split('%0A');
arr.join("");
var arr2 = arr.slice(1,arr.length-1);
gs.print( decodeURIComponent(arr2).replaceAll(',',""));
}
- To test the script I have considered taking input from description a multiline text field from incident table.
- This will work for any number of input lines.
Approach:
- Take the input from multiline text field, encode the entire string.
- %0A is the encoded value for enter, so split the encoded string wrt %0A and then slice the first and the last line.
Result:
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2025 01:28 AM
Thanks Juhi,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 10:45 AM
This gets close as long as you don't have multiple line breaks
/Hello.World.please.pick.me.from/s
If you could simply parse out the line breaks before you ran the match it would be trivial, but it seems from your example output you need to retain them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 10:48 AM
Sorry, this ->
/Hello.World.please.pick.me.from.the.annoying.bla/s
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 11:15 AM
This is actually a little more accurate -
/Hello\sWorld\splease\spick\sme\sfrom\sthe\sannoying\sbla/
If you need to account for multiple concurrent line breaks, you could use \s+ instead of \s
Fascinating problem that doesn't exist in some other languages like C# where there is a flag to just ignore all line breaks. The \m flag in javascript seems to only work in conjuction with $ and ^