Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Preload body of email with JavaScript

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

  • Verified answer
    hhertoghe Profile Picture
    hhertoghe 25 on at
    RE: Preload body of email with JavaScript

    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.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Preload body of email with JavaScript

    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

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Preload body of email with JavaScript

    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).

  • hhertoghe Profile Picture
    hhertoghe 25 on at
    RE: Preload body of email with JavaScript

    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 ?

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Preload body of email with JavaScript

    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
    hhertoghe 25 on at
    RE: Preload body of email with JavaScript

    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.

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Preload body of email with JavaScript

    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?

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

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans