Search code examples
c#.netodatadynamics-crm-2011crm

Retrieving all resources for a given ServiceAppointment with Odata


Given a specific activity, let's say it is the ServiceAppointment, how do we retrieve all the resources associated to it?

I know that the ActivityPartySet stores the relationships between the activity and the partyid.

Every ServiceAppointment may have 1 or more resources. Each resource has a partyid.

Is it possible to use odata (OrganizationData.svc) in order to retrieve all the resources for a specific ServiceAppointmnet?

I have tried to use the odata query designer in order to generate the query and was not succesful.

How do you retrieve all the resources for a specified activity using odata?


Solution

  • You can retrieve all resources of type user with the following advanced find query:

    Advanced find of users assigned as resources to a specific Service Activity

    As you can see, we need to filter on two things: The guid of the Service Activity (serviceappointment) and the Participation Type on the Activity Party (otherwise we get both resources and owners).

    We cannot have both conditions in OData. The closest we can get is something like the following:

    OrganizationData.svc/ActivityPartySet?
    $select=PartyId&
    $filter=serviceappointment_activity_parties/ActivityId eq (guid'<guid-here>')
    

    This query retrieves all Activity Parties that are related to the given Service Activity. Unfortunately, the query includes resources as well as the owner of the Service Activity. If this is not acceptable you should look into querying with one of the other webservices.