web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Preload body of email with JavaScript

(0) ShareShare
ReportReport
Posted on by 25

Dear,

I had a Javascript function that was executed onLoad of the email form to prefill the body of the email with a customized text.

This was working perfectly since a long time. Today, I see that this is not working anymore ? Any ideas ?

Version of D365: Version 1710 (9.1.0.23470) online

My code:

    console.log(body)
    Xrm.Page.getAttribute("description").setValue('');
    Xrm.Page.getAttribute("description").setValue(body);
    console.log(Xrm.Page.getAttribute("description").getValue())

I can confirm that the first console output gives the expected body and that the last console output gives as well the expected output but nothing is visible in the editable body of the email.

I have the impression that there was an update to the body form of the email. 

Do someone has the same issue? Do you see any workarounds ?

Thanks,


Henry

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    I will suggest you to debug your code and run code step by step to see what is the issue, any error on the console?

  • hhertoghe Profile Picture
    25 on at

    This is exactly what I did. No errors in the console. Again this code was working for a long time. Today I see that it's not working anymore ... nothing is displayed in the form ... it's like there was some changes in the front of D365.

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Could you please share the body text which you are setting to Email Body field?

    Have you tried in other browser and checked if it works?

    I have added below code on Email Form OnLoad and it works as expected.

    function emailOnLoad(executionContext)
    {
    	var body ="Some random Test and customized text";
    	var formContext=executionContext.getFormContext();
    	console.log(body)
        formContext.getAttribute("description").setValue('');
        formContext.getAttribute("description").setValue(body);
        console.log(formContext.getAttribute("description").getValue());
    }

    CQ53.PNG

    I am using formcontext instead of Xrm.Page because it is deprecated.

    Please mark my answer verified if i were helpful

  • hhertoghe Profile Picture
    25 on at

    Hmm weird. I tried with your code, and nothing was shown in the body of the email:

    pastedimage1602680887151v1.png

    Which version of D365 do you have ?

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    This is not code issue even though you are using  old code but still it will be working without any issue, just tested it.

    I will suggest you to recheck your email entity form, fields, code event and make sure you are checking the same form where you have the code (may be there is two forms and you are looking wrong one).

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    HI,

    Apart from what suggested by Mahen, check if you have any other code which is overriding the description field value.

    I have checked in Online version but it should on your instance too.

    Please mark my answer verified if i were helpful

  • Verified answer
    hhertoghe Profile Picture
    25 on at

    I am using the Online version as well.

    I can confirm that I was on the correct Form and that the code was executing correctly ... but nothing was shown on the email body.

    The email body is taking time to load so my guess was that I was maybe a loading issue => JS is executed, then HTML body is loaded, and so it was not showing the expected text.

    My solution = setTimeout on the loading of the execution of the JS script. Now it's working ;)

    Thanks for your help.

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 67

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 37 Super User 2025 Season 2

#3
Pallavi Phade Profile Picture

Pallavi Phade 24

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans