Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
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,962 Moderator 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,041 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,962 Moderator 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,041 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,564 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,651 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans