Luís Rodrigues
Luís Rodrigues

Reputation: 1

How to filter records from Activityparties table where the party lookup field is related to a systemuser using Web API

I'm querying appointment participants, from Dynamics 365 CRM, from the "Required Attendees" lookup field in the Appointments. I've created a query that returns records from the "activityparties" table, where "participationtypemask" equals 5 (Required Attendee). I've tried to apply a second filter to only return records where the party is a user, but the filter is ignored and I get records with all parties (accounts, contacts, cases, etc.).

This is my query:

OData.Feed("https://ar.api.crm4.dynamics.com/api/data/v9.2/" &
        "activityparties?" & 
        "$select=_activityid_value, participationtypemask, _partyid_value,&" &
        "$expand=
            partyid_systemuser($select=_amo_teamcompanynumber_value)&"
        &
        "$filter= participationtypemask eq 5 and partyid_systemuser ne null", 
        null, [Implementation="2.0", IncludeAnnotations="*"]),

The filter partyid_systemuser ne null as no effect.

How can I change this filter to only get records where the party is a systemuser?

Upvotes: 0

Views: 429

Answers (1)

Andrew Butenko
Andrew Butenko

Reputation: 5446

I would recommend using FetchXml to get the data. Here is what I came up with:

<fetch>
  <entity name="systemuser">
    <attribute name="systemuserid" />
    <link-entity name="activityparty" from="partyid" to="systemuserid" link-type="inner">
      <filter>
        <condition attribute="participationtypemask" operator="eq" value="5" />
      </filter>
    </link-entity>
  </entity>
</fetch>

Upvotes: 0

Related Questions