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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Convert Email To Case in Outlook - plugin

(0) ShareShare
ReportReport
Posted on by

I'm trying to write a plugin that will copy the description of the email into the description of a case when using the standard conver-to-functionality present in the Outlook client.

I've registered my plugin with Create on the case entity which triggers, but when I'm trying to find the email related to the case I'm getting no returns. I'm using a query expression, and here is my code:

Entity currCase = service.Retrieve("incident", entity.Id, new ColumnSet(new string[] { "incidentid", "description" }));

                    QueryExpression query = new QueryExpression();
                    // Setup the query for the email entity
                    query.EntityName = "email";
                    // Specify the columns to retrieve
                    ColumnSet columns = new ColumnSet(new string[] { "activityid", "description", "regardingobjectid", "subject" });
                    query.ColumnSet = columns;
                    query.Criteria = new FilterExpression();
                    query.Criteria.FilterOperator = LogicalOperator.And;
                    ConditionExpression condition = new ConditionExpression("regardingobjectid", ConditionOperator.Equal, new Guid(currCase["incidentid"].ToString()));
                    query.Criteria.AddCondition(condition);

                    EntityCollection emails = service.RetrieveMultiple(query);


why is this code returning 0, zero, emails? When I open the case the email is there!!

My second approach to this use two events, Create of case, and update on email. But when doing almost the excact same thing I'm getting 5000 emails in return. I'm able get the correct description, but when my query expression is returning 5000 rows, I know there is something wrong...

Entity currEmail = service.Retrieve("email", entity.Id, new ColumnSet(new string[] { "activityid", "regardingobjectid", "description" }));
Guid regardingGuid = ((EntityReference)currEmail["regardingobjectid"]).Id;

QueryExpression query = new QueryExpression();
query.EntityName = "incident";
ColumnSet columns = new ColumnSet(new string[] { "incidentid", "description" });
query.ColumnSet = columns;
query.Criteria = new FilterExpression();
query.Criteria.FilterOperator = LogicalOperator.And;
ConditionExpression condition = new ConditionExpression("incidentid", ConditionOperator.Equal, regardingGuid);
query.Criteria.AddCondition(condition);
EntityCollection incidents = service.RetrieveMultiple(query);

if (incidents.Entities.Count == 1) {
	foreach (Entity inc in incidents.Entities) {
		QueryExpression emailQuery = new QueryExpression();
		emailQuery.EntityName = "email";
		ColumnSet cols = new ColumnSet(new string[] { "activityid", "regardingobjectid" });
		emailQuery.ColumnSet = cols;
		emailQuery.Criteria = new FilterExpression();
		emailQuery.Criteria.FilterOperator = LogicalOperator.And;
		ConditionExpression cond = new ConditionExpression("regardingobjectid", ConditionOperator.Equal, new Guid(inc["incidentid"].ToString()));
		query.Criteria.AddCondition(cond);
		EntityCollection emails = service.RetrieveMultiple(emailQuery);
		inc["description"] = HTMLToText(currEmail.Attributes["description"].ToString()) + " :: " + emails.Entities.Count.ToString() + " :: " + inc["incidentid"].ToString();
		service.update(inc);
	}
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Convert Email To Case in Outlook - plugin

    Have you tried with workflows ?

  • Community Member Profile Picture
    on at
    RE: Convert Email To Case in Outlook - plugin

    Hi,

    Have you tried using postImage?

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans