{Power 2022} Extract Text out of Rich Text editor control using JavaScript in Dynamics 365 CE

Requirement: Extract text out of rich text editor control text on a Dynamics 365 CE Record form.

Here is the script for this example (written on change event):

function onChange(executionContext)
{

var formContext = executionContext.getFormContext();
formContext.getAttribute("new_plaintextwithhtml").setValue(formContext.getAttribute("new_htmlrichtext").getValue());
formContext.getAttribute("new_texteditorcontrol").setValue(convertToPlain(formContext.getAttribute("new_htmlrichtext").getValue()));


}

function convertToPlain(html){

    // Create a new div element
    var tempDivElement = document.createElement("div");
    
    // Set the HTML content with the given value
    tempDivElement.innerHTML = html;
    
    // Retrieve the text property of the element 
    return tempDivElement.textContent || tempDivElement.innerText || "";
}

Hope it helps!

Power 365ing as usual!

Other ways to learn with me:

Any problem in Power Platform or Dynamics 365 – end user, Microsoft partner or an individual?

Problem Area – Technical, Functional, Training, Development or consulting?

Me and my team are here to assist, please fill the following form for your business needs: Click here

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s