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 :
Microsoft Dynamics CRM (Archived)

How to get a list of emails with no attachment?

(0) ShareShare
ReportReport
Posted on by 423

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:
emailwithnoattachment.png

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

I have the same question (0)
  • Verified answer
    mvilas02 Profile Picture
    356 on at

    hi , 

    Why dont you try and check "attachmentcount" attribute  ?

    Regards,

    Vilas

  • bernhards Profile Picture
    423 on at

    That is the solution I was not able to find via Google. Thank you very much!

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans