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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Replace function remove new line

(0) ShareShare
ReportReport
Posted on by 458

Hi there all experts.
Recently I have write a JS that modify the description of the quote.
The functionality works fine,
But I do now know why it removes the new line character(/n).

My description is sentence by sentence.
At the beginning of each sentence there is  a dash character (-).

Here is the script.

function addServices(ServiceNames) {
    var descriptionAttribute=Xrm.Page.getAttribute("description");
    var descFieldText = descriptionAttribute.getValue();
    var txt=validateIfExist(descFieldText); // It search for a specified sentence in the description and return that if that exist.
     if(ServiceNames) {
		if(txt) {
    descFieldText=descFieldText.replace(txt, "It Includes : " 
      arvandServiceNames); 
    descriptionAttribute.setValue(descFieldText); 
    Xrm.Page.data.entity.save();   
		}
	 }
  }

It works fine and replace the description with desired text.
But It removes all the new line(/n).

How can I handle it so that I can keep new line?

Any help will be appreciated.

I have the same question (0)
  • Filipe Relvas Profile Picture
    on at

    Hey Albert,

    Unfortunately from what you shared it is hard to give a concrete answer.

    This really depends on how the description / string is stored in the Database.

    I would start by checking the Quote Description attribute from the WebAPI in order to understand how the newlines are stored: https://<orgname>.crm<region>.dynamics.com/api/data/v9.1/quotes(<quoteid>)

    It is also important to check the final value of the "descFieldText" after the replace with "It Includes : " + arvandServiceNames. We don't know the content of "arvandServiceNames" so this might also require a quick check.

    If you have additional info based on this please let us know so we can help you further.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans