The difference of new line code

Mackey
Tera Contributor

Hello.

I wrote a sentence includes new line in a multi-line text box field in a form.

Then, I wrote the same sentence includes new line in a multi-line text box field in a list using list edit function.

I compare the number of length of sentences between these fields and these numbers are different.

By my research, new line codes in the former sentence was "\r\n", but the latter was "\n" and this difference caused the difference of the number of length.

Why are these difference? What cause is created the difference?

Thank you.

3 REPLIES 3

Hitoshi Ozawa
Giga Sage
Giga Sage

That's just the specification.

If I edit the field in the list cell editor and then edit to add a new row from the form, all the carriage returns will be converted to \r\n. If I edit the field in the list cell editor again, all the carriage returns will be converted to \n.

If there is a need to strictly use only \n, create a business rule to convert \r\n to \n.

Hi Hitoshi,

Thank you for your reply.

Do you know what causes the defference?
Is it by JavaScript?, Java?, mySQL?, or ServiceNow unique specification?

If you know, plase let me know.

Thank you.

Not sure but I think it's just the JavaScript UI component that's being used. May be developed by some different team?

It seems like JavaScript internally will treat \r\n and \n to be the same so it shouldn't be too much of a problem.

Can't run this in Background script, but can run it on jsfiddle. This will result in "true, true, true".

let a = eval("`abc\ndef`");
let b = eval("`abc\r\ndef`");
let c = "abc\ndef";
console.log(a == b, b== c, a == c);