Newlines in Journal Fields via Script?

rushputin
Mega Expert

I'm working on a Transform Map, and I've got a good handful of fields that don't quite have an appropriate target field, so I'd like to stitch them together and write them all to a journal field (Work Notes, specifically).   Ideally, I'd do this with

 

target.work_notes = "[Column A Name]\n" + source.column_a + "\n\n" +

                                      "[Column B Name]\n" + source.column_b;

 

to get:

 

[Column A Name]:

[Column A Value]

 

[Column B Name]:

[Column B Value]

 

The trick is: nothing past the first newline gets written to the field.   I just end up with

 

[Column A Name]:

 

and nothing else.

 

This makes some sense: I know I parse journals into individual entries by splitting them on "\n\n"; but I also know that I can enter newlines from the actual interface and it handles them just fine; and it's stopping at the first "\n".

 

Sure, I could do

[Column A Name]: [Column A Value] [Column B Name]: [Column B Value]

 

But that just looks bad, doesn't it?

 

So: how do I indicate, via a script, that I'd like there to be a newline within a single journal entry?

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

I believe the problem is you should have a leading "u_" for the column names:



target.work_notes = "[Column A Name]\n" + source.u_column_a + "\n\n" + "[Column B Name]\n" + source.u_column_b;


View solution in original post

4 REPLIES 4

Jim Coyne
Kilo Patron

I believe the problem is you should have a leading "u_" for the column names:



target.work_notes = "[Column A Name]\n" + source.u_column_a + "\n\n" + "[Column B Name]\n" + source.u_column_b;


You know, I don't think it was the missing "u_" (the above was just stuff I wrote to demonstrate what I was doing), but it did turn out to be some stupid javascript syntax error that I missed thanks to fixating on the newline thing.



Thanks!


Faisal Reza
Giga Contributor

Maybe the other guys are able to get "\n" to work but this is an old thread so maybe it's no longer working in latest OOTB ServiceNow? At least it is not working for me...

So I instead added the following to the string anytime i needed a line break to show up:

"[code]<br />[/code]"

Faisal Reza
Giga Contributor

Maybe the other guys are able to get "\n" to work but this is an old thread so maybe it's no longer working in latest OOTB ServiceNow? At least it is not working for me...

So I instead added the following to the string anytime i needed a line break to show up:

"[code]<br />[/code]"