locked
Dynamics 365 - set email body / description through Javascript RRS feed

  • Question

  • Hi everyone, anyone try to set Xrm.Page.getAttribute("description").setValue(field) in Dynamics 365?

    I can see we js variables that my custom strings are added but are not showed in the description editor.. any suggestion?

            console.log(Xrm.Page.getAttribute("description").getValue()); //original body
    Xrm.Page.getAttribute("description").setValue("TEST");
    console.log(Xrm.Page.getAttribute("description").getValue()); //TEST

    HTML editor continues showing the original body. Any ideas?

    Wednesday, September 20, 2017 7:51 AM

All replies

  • Hi Alessandro, 

    What is exactly the HTML editor , a field in the form or a custom field from a web resource ?  Are you sur that "description" is the Html editor that you try to change ? 

    Kind Regards, 

    Mohamed

    Thursday, September 21, 2017 11:42 AM
  • Hi, I use standard email form. The email body is the description field of email entity.

    I'm trying to modify it by custom JS adding some text.

    Alex

    Thursday, September 21, 2017 12:08 PM
  • it's because the description in the email form is as a IFrame. Look this link : https://nishantrana.me/2009/08/25/email-description-field-body-field-and-javascript-in-crm/
    • Proposed as answer by Moh Helper Thursday, September 21, 2017 12:25 PM
    Thursday, September 21, 2017 12:25 PM
  • That's valid for CRM4 not for CRM2011 and later versions...
    Thursday, September 21, 2017 12:32 PM
  • sorry I didn't see the version. I have seen on a forum that the description is sometimes loaded after the form is loaded.

    So one of solution will be to wait for the content of the body. A example of method who could help you : 

    var checkExist = setInterval(function() {
       if ($('elementBody').length) {
          console.log("Exists!");
          clearInterval(checkExist);
       }
    }, 100);
    
    //then
    Xrm.Page.getAttribute("description").setValue("TEST");

    The interval solution is really a bad solution and should be used only if nothing else works. 


    Thursday, September 21, 2017 1:24 PM