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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Cannot read reply text in email from Plugin

(0) ShareShare
ReportReport
Posted on by 352

Hi, I have a plugin on Create event for the email entity. Its purpose is adding some content into the email body before sending it and in order to accomplish that I read the "description" attribute, perform the changes and update back that attribute.

Everything works like a charm when I create a new email, however, when I reply an existing email, the plugin is fired but when I read the description attribute it is only getting the original content and not the text we add as a reply. Am I missing something?

I would appreciate your advise.

Xavier

I have the same question (0)
  • Joana Pinto Profile Picture
    740 on at

    Hi,

    Could you provide a piece of your code please? And you plugin is fired on Pre or Post event?

    Thanks.

  • Xavier Villafuerte Profile Picture
    352 on at

    Hi Joana, thanks for your time. The plugin is fired on Post-operation. The relevant part of my code is as follows:

    if (context.InputParameters != null)

               {

                   Entity entity = (Entity)context.InputParameters["Target"];

                   try

                   {

                       if (entity.LogicalName == "email")

                       {

                           bool directionCode = entity.GetAttributeValue<bool>("directioncode");

                           if (directionCode) //true is outgoing

                           {

                               string emailBody = entity.GetAttributeValue<string>("description");

    After that I use the variable emailBody in a process so its content is changed and the new value is used to update the attribute "description" in "entity". My trace log shows the emailBody variable never gets the reply text when the plugin is fired after a reply but, if I created an completely new email, the variable gets the email body correctly and everything works as expected.

    Thanks for your advise.

    Xavier

  • Joana Pinto Profile Picture
    740 on at

    So, in both scenarios, does you code get to this part?

    string emailBody = entity.GetAttributeValue<string>("description");

  • Xavier Villafuerte Profile Picture
    352 on at

    Yes Joana.

  • Joana Pinto Profile Picture
    740 on at

    Can you provide the full code that updates the entity please? I think maybe it has to do with something regarding the update but I have to see the code.

  • Xavier Villafuerte Profile Picture
    352 on at

    Sure, see below:

    if (apiResponse.success == "1")

                                   {

                                       entity["description"] = apiResponse.emailBody;

                                       service.Update(entity);

                                       log.Trace("Email body updated successfully.");

                                   }

    However, as far as I can see the main problem is not in the update process because the trace shows that when the plugin fires, the email body read by the plugin does not contain the user-typed reply text. So the remaining parts of the code, including the update, works with the incorrect body. When the plugin fires for a newly created email, everything works fine.

  • Verified answer
    Joana Pinto Profile Picture
    740 on at

    Hi,

    I suggest you to check the audit of the field to see the values on the different events (create, update, etc) and see if it helps.

    Regards,

    Joana

  • Xavier Villafuerte Profile Picture
    352 on at

    You were right. After checking the audit for the email, I noticed that on Create, the description field did not have the reply text and only after an Update, the CRM appends to it the reply text. So, as my plugin only fires on Create, it won´t read the updated description field and that is the origin of my problem. I will fix this on my side. Thanks for your valuable help Joana.

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

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans