locked
Query Expression In C# : Quering CRM entity with EntityReference in ConditionExpression RRS feed

  • Question

  • Hello friends,

    I am trying to get appointment data using C# code (using QueryExpression). I have to add below condition :

    "OptionalAttendees should contain <<SomeId Value>>..."

    I tried lot to write this QueryExpression but not getting any success.

    Please help me


    Vijay Sutaria

    Monday, September 30, 2013 2:58 PM

Answers

  • You can achieve this using FetchExpression. The following example looks for Appointments where the given Contact is an optional attendee.

    Guid contactId = new Guid("0101A2D1-4CF2-E211-840D-005056824F19");
    
    string xml = @"
    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
        <entity name='appointment'>
        <attribute name='subject' />
        <order attribute='subject' descending='false' />
        <link-entity name='activityparty' from='activityid' to='activityid' alias='aa'>
            <filter type='and'>
            <condition attribute='participationtypemask' operator='eq' value='6' />
            <condition attribute='partyid' operator='in'>
                <value uitype='contact'>{D4806BF5-63EB-E211-840D-005056824F19}</value>
                <value uitype='contact'>{0101A2D1-4CF2-E211-840D-005056824F19}</value>
            </condition>
            </filter>
        </link-entity>
        </entity>
    </fetch>
    ";
    
    FetchExpression fetch = new FetchExpression(xml);
    EntityCollection results = _service.RetrieveMultiple(fetch);

    The "participationmask" of 6 refers to "optional attendees". 

    I hope this answers your question.


    Please feel free to contact me via any of the following methods:

    • Proposed as answer by Roshan Mehta Monday, September 30, 2013 8:05 PM
    • Marked as answer by Sutaria Vijay Tuesday, October 1, 2013 6:29 AM
    Monday, September 30, 2013 8:05 PM

All replies

  • You can achieve this using FetchExpression. The following example looks for Appointments where the given Contact is an optional attendee.

    Guid contactId = new Guid("0101A2D1-4CF2-E211-840D-005056824F19");
    
    string xml = @"
    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
        <entity name='appointment'>
        <attribute name='subject' />
        <order attribute='subject' descending='false' />
        <link-entity name='activityparty' from='activityid' to='activityid' alias='aa'>
            <filter type='and'>
            <condition attribute='participationtypemask' operator='eq' value='6' />
            <condition attribute='partyid' operator='in'>
                <value uitype='contact'>{D4806BF5-63EB-E211-840D-005056824F19}</value>
                <value uitype='contact'>{0101A2D1-4CF2-E211-840D-005056824F19}</value>
            </condition>
            </filter>
        </link-entity>
        </entity>
    </fetch>
    ";
    
    FetchExpression fetch = new FetchExpression(xml);
    EntityCollection results = _service.RetrieveMultiple(fetch);

    The "participationmask" of 6 refers to "optional attendees". 

    I hope this answers your question.


    Please feel free to contact me via any of the following methods:

    • Proposed as answer by Roshan Mehta Monday, September 30, 2013 8:05 PM
    • Marked as answer by Sutaria Vijay Tuesday, October 1, 2013 6:29 AM
    Monday, September 30, 2013 8:05 PM
  • Thank a lot Roshan , It works for me.

    Vijay Sutaria

    Tuesday, October 1, 2013 6:29 AM