Thursday 21 September 2023

Remove Html Div tags from comments and save in another field - Dynamics CRM

 CODE: 

function onChangeComments(executionContext) {
var formContext = executionContext.getFormContext();
var new_comments = convertToPlain(formContext.getAttribute("new_comments").getValue());

 

formContext.getAttribute("new_copycomments").setValue(new_comments);
}

 

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 || "";
}

No comments:

Post a Comment

Git Basic working