How to get a list of specific E-Mails with no attachment?
Since I read that, the advanced search is not longer a option:
community.dynamics.com/.../199988
Anyway, I tried it with a specific email, and even when this e-mail does not contain a attachment it was in the list:
<fetch> <entity name="email" > <filter> <condition attribute="senton" operator="on-or-after" value="2018-04-01" /> <condition attribute="wd_activity_type" operator="eq" value="100000016" /> <condition attribute="statuscode" operator="eq" value="3" /> <condition attribute="activityid" operator="eq" value="C5E6EA35-C788-E811-A2B8-00505687C621" /> </filter> <link-entity name="annotation" from="annotationid" to="activityid" link-type="outer" > <filter> <condition attribute="annotationid" operator="null" /> </filter> </link-entity> </entity> </fetch>
Here's the email:
It tried it with C#/SDK but no success:
public void Retrieve_Emails_Without_Attachment() { string connectionString = "AuthType=AD;Url=http://URL/ORG"; CrmServiceClient conn = new CrmServiceClient(connectionString); IOrganizationService service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; string emailXml = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\">" + " <entity name=\"email\">" + " <attribute name=\"subject\" />" + " <attribute name=\"regardingobjectid\" />" + " <attribute name=\"activityid\" />" + " <attribute name=\"from\" />" + " <attribute name=\"to\" />" + " <attribute name=\"statuscode\" />" + " <attribute name=\"modifiedon\" />" + " <attribute name=\"activityid\" />" + " <attribute name=\"senton\" />" + " <attribute name=\"createdby\" />" + " <attribute name=\"createdon\" />" + " <order attribute=\"subject\" descending=\"false\" />" + " <filter type=\"and\">" + " <condition attribute=\"wd_activity_type\" operator=\"eq\" value=\"100000016\" />" + " <condition attribute=\"statuscode\" operator=\"eq\" value=\"3\" />" + " <condition attribute=\"senton\" operator=\"on-or-after\" value=\"2018-04-01\" />" + " </filter>" + " </entity>" + "</fetch>"; // MS named attachments as annotations for whatever reason string annotationXml = "<fetch>" + " <entity name=\"annotation\" >" + " <filter>" + " <condition attribute=\"createdon\" operator=\"gt\" value=\"2018-04-01\" />" + " <condition attribute=\"filename\" operator=\"ends-with\" value=\"ikkey\" />" + " </filter>" + " </entity>" + "</fetch>"; List<Entity> emails = RetrieveAllRecordsFromAllPages(service, emailXml); List<Entity> attachments = RetrieveAllRecordsFromAllPages(service, annotationXml); List<Guid> emailsWithAttachment = new List<Guid>(); List<Guid> emailsWithNoAttachment = new List<Guid>(); foreach(Entity email in emails) { Guid emailRegardingObjectId = email.GetAttributeValue<EntityReference>("regardingobjectid") != null ? email.GetAttributeValue<EntityReference>("regardingobjectid").Id : Guid.Empty; if(emailRegardingObjectId != Guid.Empty) { foreach(Entity attachment in attachments) { int filesize = attachment.GetAttributeValue<int>("filesize"); Guid noteRegardingObjectId = attachment.GetAttributeValue<EntityReference>("objectid") != null ? attachment.GetAttributeValue<EntityReference>("objectid").Id : Guid.Empty; if (emailRegardingObjectId == noteRegardingObjectId) { if (filesize < 1) { emailsWithNoAttachment.Add(emailRegardingObjectId); break; } else { emailsWithAttachment.Add(emailRegardingObjectId); break; } } } } } }
*This post is locked for comments
That is the solution I was not able to find via Google. Thank you very much!
hi ,
Why dont you try and check "attachmentcount" attribute ?
Regards,
Vilas
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156