- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 09:32 PM
how to get the count of lines from multi line text string, I tried below but its returing undeined instead of 2
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:40 PM
User might have entered extra 'ENTER' so it is adding extra line at the end.
You can use logic like below:
var current = new GlideRecord('change_request');
current.get('fdbce3f72f323110ae17debcf699b65c');
var itar = current.variables.existing_itar_objects.toString().trim(); // use toString() to change it to string
var lineCount = itar.split('\n').length;
gs.info(lineCount);
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 09:58 PM
Hello @mounika32
Please use this script -
var itar = current.variables.existingg_itar_object;
var linesArray = itar.split('\n');
var lineCount = linesArray.length;
gs.info('Number of lines in the multi-line text: ' + lineCount);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:33 PM
Hello @mounika32
Please use this-
var gr = new GlideRecord('sc_req_item');
gr.get('3fc5485497433110cf05f8971153af79');
var itar = gr.variables.software_requirements.toString();
var linesArray = itar.split('\n');
var lineCount = linesArray.length;
gs.info('Number of lines in the multi-line text: ' + lineCount);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:07 PM
Hi @mounika32 ,
Try Below script -
var chatHistory = "Line 1\nLine 2\nLine 3\nLine 4";
var lines = chatHistory.split('\n');
var lineCount = lines.length;
gs.info(lineCount);
Thanks and Regards,
Rahul
Thanks and Regards,
Rahul