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 452

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.

  • Filipe Relvas Profile Picture
    on at
    RE: Replace function remove new line

    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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 113 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Sahra Profile Picture

Sahra 43

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans