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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to retrieve Emails based on Contact Guid or Email id using Fetch XML ?

(0) ShareShare
ReportReport
Posted on by 483

Hello,

I want Emails based on Contact Email Id from Email entity using To Field but when iam using To field as Condition in fetch xml getting error as "Cannot add attribute to of type partylist in a condition ". Please suggest some solution how to use To field in Fetch XML to get Emails.

Thanks,

Krishna

*This post is locked for comments

I have the same question (0)
  • Mick_4711 Profile Picture
    552 on at

    Hi Krishna,

    could you try this? (Sorry.... here's the edited Version)

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
      <entity name="email">
        <attribute name="subject" />
        <attribute name="regardingobjectid" />
        <attribute name="prioritycode" />
        <attribute name="statuscode" />
        <attribute name="modifiedon" />
        <attribute name="activityid" />
        <order attribute="subject" descending="false" />
        <link-entity name="activityparty" from="activityid" to="activityid" alias="ap">
          <link-entity name="contact" from="contactid" to="partyid" alias="aq" />
        </link-entity>
        <link-entity name="contact" from="contactid" to="regardingobjectid" visible="false" link-type="outer" alias="a_695c5e4d7fb6410289fff0850df9ac07">
          <attribute name="emailaddress1" />
        </link-entity>
        <link-entity name="contact" from="contactid" to="emailsender" visible="false" link-type="outer" alias="a_00ed57ad1f2b405d914265d2f4298447">
          <attribute name="emailaddress1" />
        </link-entity>
      </entity>
    </fetch>

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Krishna,

    This is expceted behaviour. You cannot query partilist. You can however use "ToRecipient" field.

    =======================

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

     <entity name="email">

       <attribute name="subject" />

       <attribute name="regardingobjectid" />

       <attribute name="from" />

       <attribute name="to" />

       <attribute name="prioritycode" />

       <attribute name="statuscode" />

       <attribute name="modifiedon" />

       <attribute name="activityid" />

       <order attribute="subject" descending="false" />

       <filter type="and">

         <condition attribute="torecipients" operator="eq" value="ravi.kashyap@gmail.com" />

       </filter>

     </entity>

    </fetch>

    =======================

    Hope this helps.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    The easiest way if you can get the email address is this one:

    <?xml version="1.0"?>

    <fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">

    <entity name="email">

    <attribute name="subject"/>

    <attribute name="regardingobjectid"/>

    <attribute name="from"/>

    <attribute name="to"/>

    <attribute name="prioritycode"/>

    <attribute name="statuscode"/>

    <attribute name="modifiedon"/>

    <attribute name="activityid"/>

    <order descending="false" attribute="subject"/>

    <filter type="and">

    <filter type="or">

    <condition attribute="torecipients" operator="like" value="%myemail@me.com%" />

    <condition attribute="torecipients" operator="like" value="%youremail@me.com%" />

    </filter>

    </filter>

    </entity>

    </fetch>

    The more complex way is this if you want to use guid:

    <fetch distinct="false" no-lock="false" top="10" mapping="logical">
    <entity name="email">
    <attribute name="subject"/>
    <attribute name="regardingobjectid"/>
    <attribute name="from"/>
    <attribute name="to"/>
    <attribute name="prioritycode"/>
    <attribute name="statuscode"/>
    <attribute name="modifiedon"/>
    <attribute name="activityid"/>
    <filter type="and">
    <condition attribute="statecode" operator="eq" value="0" />
    </filter>
    <link-entity name="activityparty" to="activityid" from="activityid" link-type="inner" alias="ap">
    <filter type="and">
    <condition attribute="participationtypemask" operator="eq" value="2" />
    </filter>
    <link-entity name="contact" to="partyid" from="contactid" link-type="inner" alias="ca">
    <filter type="and">
    <condition attribute="contactid" operator="eq" value="{97C4DEF9-E845-4755-8F3D-554D26052DD8}" />
    </filter>
    </link-entity>
    </link-entity>
    </entity>
    </fetch>

    participationtypemask sender:1, to:2, cc:3, bcc:4

  • Suggested answer
    dkrishna Profile Picture
    483 on at

    Thanks it works !!

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Krishna,

    Please mark the suggestion which helped you so that it can help others looking fr the same/ similar issue.

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

News and Announcements

Season of Giving Solutions is Here!

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