Friday 14 June 2013

Copy Rich Text Box field content into a text field with JavaScript (CRM 2011)

Richtextbox fields content (for example the body of an email activity) is a mix of text and tags: when copying its content into another CRM field of type Text, the destination field will contain also the tags.
Because the representation of a Textbox field is a simple string and it is not formatted as in the case of a Richtextbox, the result is that the text showed is similar to an HTML content.
This is not user friendly for CRM users, therefore we should remove all the tags and let only the original content; obviously, we will lose the formatting (bold, underline, etc...).
We can do that with JavaScript, using the regular expressions, as shown below:


var richTextBoxContent =
    Xrm.Page.getAttribute("richtextbox_attribute_name").getValue();
var richTextBoxContentStripped =
    richTextBoxContent.replace(/(<([^>]+)>)/ig, '');

Xrm.Page.getAttribute("text_attribute_name").setValue(richTextBoxContentStripped);


Hope it can be useful.
Happy CRM coding.
Rate this posting:
{[['']]}

2 comments:

  1. You can visit this website and find out more info about MS codes. More helpful info and tips for you.

    ReplyDelete
  2. On my website you'll see similar texts, write what you think. database management

    ReplyDelete