\n Line break not working in UI Action script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 08:08 AM
I have a script in a UI action that copies the work notes from one record into a new one. I'm adding on to a string using '+=' but it is not rendering the new lines when I use '\n'. \n works fine when I use it in other scripts, but for some reason not here. Below is the relevant part of the script, and a screenshot of how it is currently resolving.
var new_notes = '';
var old_notes = new GlideRecord('sys_journal_field');
old_notes.addQuery('element_id', current.sys_id);
old_notes.addQuery('element', 'work_notes');
old_notes.orderByDesc('sys_created_on');
old_notes.query();
while (old_notes.next()) {
new_notes += old_notes.sys_created_by + ' - ' + old_notes.sys_created_on + ' - ' + old_notes.value + '\n\n';
}
This is how it currently renders the work notes in the new record. You can see 4 individual notes (test notes 1, test notes 2, etc.) but it does not add any space between them.
BradFournier - 2017-11-28 16:19:41 - test notes 4BradFournier - 2017-11-28 16:19:31 - test notes 3BradFournier - 2017-11-28 16:19:20 - test notes 2BradFournier - 2017-11-28 16:19:09 - test notes 1
Looking for any help figuring out why it's not adding line breaks where I have '\n\n' at the end of the string.
Thanks!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 08:23 AM
Please modify your code like below
- var new_notes = '';
- var old_notes = new GlideRecord('sys_journal_field');
- old_notes.addQuery('element_id', current.sys_id);
- old_notes.addQuery('element', 'work_notes');
- old_notes.orderByDesc('sys_created_on');
- old_notes.query();
- while (old_notes.next()) {
- new_notes += old_notes.sys_created_by + ' - ' + old_notes.sys_created_on + ' - ' + old_notes.value + '\n'+'\n';
- }
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 08:29 AM
Hi Sachin,
Unfortunately that does not work. It renders the same way as my original code.
Thanks,
Brad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 09:14 AM
Please modify your code like below
- var old_notes = new GlideRecord('sys_journal_field');
- old_notes.addQuery('element_id', current.sys_id);
- old_notes.addQuery('element', 'work_notes');
- old_notes.orderByDesc('sys_created_on');
- old_notes.query();
- while (old_notes.next()) {
- new_notes += "\n\n" + old_notes.sys_created_by + ' - ' + old_notes.sys_created_on + ' - ' + old_notes.value
- }
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 09:18 AM
Hi Sachin,
That also renders the same way.
Thanks,
Brad