- 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:17 PM
Try the .length in a new line then check if it returns proper value or not
var linesArray = itar.split('\n'); // Get the count of lines var linesCount = linesArray.length;
Thanks,
Danish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:23 PM
Hi,
Can you please explain what type of variable it is?
And can you please show the record screenshot storing this value?
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:29 PM - edited 12-06-2023 11:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:24 PM - edited 12-06-2023 10:25 PM
Hi @mounika32 ,
Please share the snip of the variable in which data is stored please. Need to check how data is stored in that variable
Thanks,
Danish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:27 PM
Please try below:
var current = new GlideRecord('change_request');
current.get('fdbce3f72f323110ae17debcf699b65c');
var itar = current.variables.existing_itar_objects.toString(); // use toString() to change it to string
var lineCount = itar.split('\n').length;
gs.info(lineCount);
Thanks
Anil Lande