- 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 10:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:37 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: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 10:44 PM
Hi @Anil Lande , Its working now when I add the trim it returns the correct count.
Thank you for your help😀