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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get Appointment which has empty "RequiredAttendees" using FetchXML?

(0) ShareShare
ReportReport
Posted on by 351

Hi All,

I want to get all the appointments which hasn't "Required Attendees" using FetchXml.

I have written a below code for the FetchXML:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
    <entity name="appointment" >
        <attribute name="subject" />
        <attribute name="statecode" />
        <attribute name="scheduledstart" />
        <attribute name="scheduledend" />
        <attribute name="createdby" />
        <attribute name="regardingobjectid" />
        <attribute name="activityid" />
        <attribute name="instancetypecode" />
        <order attribute="subject" descending="false" />
        <link-entity name="activityparty" from="activityid" to="activityid" link-type="inner" alias="ah" >
            <filter type="and" >
                <condition attribute="participationtypemask" operator="eq" value="5" />
                <condition attribute="partyid" operator="eq" value="" />
            </filter>
        </link-entity>
    </entity>
</fetch>

Please suggest me!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    The above query will not work as you expected.

    Where do you want to use this query ? do you want to use this in code?

  • H V Profile Picture
    351 on at

    Thanks Kokulan!

    Yes, I want to use this query in code.

  • Verified answer
    Kokulan Profile Picture
    18,054 on at

    You may have to run two queries and combine the results

    Query 1 :

    Get all the active appointments with no activity party records linked at all.

    FETCH :

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

    <entity name="appointment" >
    <attribute name="subject" />
    <attribute name="statecode" />
    <attribute name="scheduledstart" />
    <attribute name="scheduledend" />
    <attribute name="createdby" />
    <attribute name="regardingobjectid" />
    <attribute name="activityid" />
    <attribute name="instancetypecode" />
    <order attribute="subject" descending="false" />
    <filter type="and" >
    <condition attribute="statecode" operator="in" >
    <value>0</value>
    <value>3</value>
    </condition>
    </filter>
    <link-entity name="activityparty" from="activityid" to="activityid" link-type="outer" alias="ab" />
    <filter type="and" >
    <condition entityname="ab" attribute="activityid" operator="null" />
    </filter>
    </entity>
    </fetch>

    C# :

    // Define Condition Values
    var QEappointment_0_statecode_1 = 0;
    var QEappointment_0_statecode_2 = 3;

    // Instantiate QueryExpression QEappointment
    var QEappointment = new QueryExpression("appointment");
    QEappointment.Distinct = true;

    // Add columns to QEappointment.ColumnSet
    QEappointment.ColumnSet.AddColumns("subject", "statecode", "scheduledstart", "scheduledend", "createdby", "regardingobjectid", "activityid", "instancetypecode");
    QEappointment.AddOrder("subject", OrderType.Ascending);

    // Define filter QEappointment.Criteria
    var QEappointment_Criteria_0 = new FilterExpression();
    QEappointment.Criteria.AddFilter(QEappointment_Criteria_0);

    // Define filter QEappointment_Criteria_0
    QEappointment_Criteria_0.AddCondition("statecode", ConditionOperator.In, QEappointment_0_statecode_1, QEappointment_0_statecode_2);
    var QEappointment_Criteria_1 = new FilterExpression();
    QEappointment.Criteria.AddFilter(QEappointment_Criteria_1);

    // Define filter QEappointment_Criteria_1
    QEappointment_Criteria_1.AddCondition("ab", "activityid", ConditionOperator.Null);

    // Add link-entity QEappointment_activityparty
    var QEappointment_activityparty = QEappointment.AddLink("activityparty", "activityid", "activityid", JoinOperator.LeftOuter);
    QEappointment_activityparty.EntityAlias = "ab";

    //Perfrom retrieve multiple to get the number of records  and keep this in a variable

    Query 2: The following query should return all the appointment with no required attendees but because of the way the FETCH query works, will include some that does have required attendees. What you have to do is to filter the results to exclude those and then merge with the list from query 1.

     

    FETCH

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
    <entity name="appointment" >
    <attribute name="subject" />
    <attribute name="statecode" />
    <attribute name="scheduledstart" />
    <attribute name="scheduledend" />
    <attribute name="createdby" />
    <attribute name="regardingobjectid" />
    <attribute name="activityid" />
    <attribute name="instancetypecode" />
    <order attribute="subject" descending="false" />
    <filter type="and" >
    <condition attribute="statecode" operator="in" >
    <value>0</value>
    <value>3</value>
    </condition>
    </filter>
    <link-entity name="activityparty" from="activityid" to="activityid" link-type="inner" alias="ag" >
    <filter type="and" >
    <condition attribute="participationtypemask" operator="ne" value="5" />
    </filter>
    </link-entity>
    </entity>
    </fetch>

    C#

    // Define Condition Values
    var QEappointment_statecode_1 = 0;
    var QEappointment_statecode_2 = 3;
    var QEappointment_activityparty_participationtypemask = 5;

    // Instantiate QueryExpression QEappointment
    var QEappointment = new QueryExpression("appointment");
    QEappointment.Distinct = true;

    // Add columns to QEappointment.ColumnSet
    QEappointment.ColumnSet.AddColumns("subject", "statecode", "scheduledstart", "scheduledend", "createdby", "regardingobjectid", "activityid", "instancetypecode");
    QEappointment.AddOrder("subject", OrderType.Ascending);

    // Define filter QEappointment.Criteria
    QEappointment.Criteria.AddCondition("statecode", ConditionOperator.In, QEappointment_statecode_1, QEappointment_statecode_2);

    // Add link-entity QEappointment_activityparty
    var QEappointment_activityparty = QEappointment.AddLink("activityparty", "activityid", "activityid");
    QEappointment_activityparty.EntityAlias = "ag";

    // Define filter QEappointment_activityparty.LinkCriteria
    QEappointment_activityparty.LinkCriteria.AddCondition("participationtypemask", ConditionOperator.NotEqual, QEappointment_activityparty_participationtypemask);

    Let me know if you need further assistance on this.

     

     

     

     

     

  • H V Profile Picture
    351 on at

    Thank you so much Kokulan for your help and your time!

    Query 1 will get all the appointments and Query 2 will give us all the appointment which has "required" is not null. I have changed the condition for the participationtypemask in "Query 2". 

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
    <entity name="appointment" >
    <attribute name="subject" />
    <attribute name="statecode" />
    <attribute name="scheduledstart" />
    <attribute name="scheduledend" />
    <attribute name="createdby" />
    <attribute name="regardingobjectid" />
    <attribute name="activityid" />
    <attribute name="instancetypecode" />
    <order attribute="subject" descending="false" />
    <filter type="and" >
    <condition attribute="statecode" operator="in" >
    <value>0</value>
    <value>3</value>
    </condition>
    </filter>
    <link-entity name="activityparty" from="activityid" to="activityid" link-type="inner" alias="ag" >
    <filter type="and" >
    <condition attribute="participationtypemask" operator="eq" value="5" />
    </filter>
    </link-entity>
    </entity>
    </fetch>


    Now, I have filtered appointment which are in List 1 but not in List 2. It gave me the result.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans