web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

getValue() on multi-line text field strips newlines -- solved

(0) ShareShare
ReportReport
Posted on by

nvm - it was a problem with the debugger. Turns out getValue() does in fact return embedded \r

I am running JavaScript that needs the value of a multi-line field verbatim, but when I fetch the value using getValue() I get a string with all lines concatenated to each other without separators.

Example:

MyField value:

First line
Second line

But when in the form I run the JS code below:

var text = Xrm.Page.getAttribute('new_myfield').getValue();

the value of text is 'First lineSecond line'


I really need the original, i.e. something like 'First line\nSecond line' or 'First line\r\nSecond line' or even 'First line<br>Second line'. This seems such a basic requirement that I think I am doing something wrong, in which case sorry for asking a dumb question, but I would appreciate if someone could point me to a working solution.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    DigitalFlow Profile Picture
    80 on at

    Hi there,

    I stumbled upon this issue in a CRM 2016 environment as well. This thread is pretty old, but just for the record:

    As it turns out, sometimes there seems to be "\r" line breaks inside those fields instead of the normal "\n" line breaks (even when entering the line breaks manually on the form).

    var text = Xrm.Page.getAttribute(...).getValue().replace(/\r/g, "\n");
    

    did the trick for me.

    You can't see those carriage returns in the debugger, only if you serialize the value to json, you will see that your lines probably contained "firstLine\rsecondLine".

    Kind Regards,

    Florian

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans