The CreatorCon Call for Content is officially open! Get started here.

\n Line break not working in UI Action script

bradfournier
Kilo Expert

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!

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

Please modify your code like below



  1. var new_notes = '';  
  2. var old_notes = new GlideRecord('sys_journal_field');  
  3. old_notes.addQuery('element_id', current.sys_id);  
  4. old_notes.addQuery('element', 'work_notes');  
  5. old_notes.orderByDesc('sys_created_on');  
  6. old_notes.query();  
  7. while (old_notes.next()) {  
  8. new_notes += old_notes.sys_created_by + ' - ' + old_notes.sys_created_on + ' - ' + old_notes.value + '\n'+'\n';  
  9. }  


Regards,


Sachin


Hi Sachin,



Unfortunately that does not work. It renders the same way as my original code.



Thanks,


Brad


Please modify your code like below



  1. var old_notes = new GlideRecord('sys_journal_field');
  2. old_notes.addQuery('element_id', current.sys_id);
  3. old_notes.addQuery('element', 'work_notes');
  4. old_notes.orderByDesc('sys_created_on');
  5. old_notes.query();
  6. while (old_notes.next()) {
  7. new_notes += "\n\n" + old_notes.sys_created_by + ' - ' + old_notes.sys_created_on + ' - ' + old_notes.value
  8. }


Regards,


Sachin


Hi Sachin,



That also renders the same way.



Thanks,


Brad