2

due to CRM 2011 online problems with IE10, we have decided to convert all front-end JavaScript from Soap to oData. Everything was going fine, I installed the oData designer, centralized the queries in functions, but i ran into a problem when i tried to retrieve the partylist field Resources for ServiceActivity.

The oData query I got using the oData Query designer is the following (the guid is a sample)

ServiceAppointmentSet?$select=Resources&$filter=ActivityId eq guid'83CA6B11-6C0A-E311-8BB5-B499BAFE71A5'

but in the response i get an error that the Resources field was not found.

I tried without the select, and debugged the returned oData object, but noticed that it doesn't show both Resources and Customers partylist fields that are in ServiceActivity.

ServiceAppointmentSet?$filter=ActivityId eq guid'83CA6B11-6C0A-E311-8BB5-B499BAFE71A5'

Does anyone have any ideas?

Bojan Borisovski
  • 877
  • 9
  • 27

2 Answers2

5

I believe you can get the Resources and Customers by using $expand to allow the query to include the serviceappointment_activity_parties relationship. Like so:

ServiceAppointmentSet(guid'83CA6B11-6C0A-E311-8BB5-B499BAFE71A5')?
  $select=
    serviceappointment_activity_parties/ParticipationTypeMask,
    serviceappointment_activity_parties/PartyId
  &$expand=serviceappointment_activity_parties

The GUID of the activityparty is found in PartyId, and the ParticipationTypeMask integer allows you to figure out what kind of activity party it is, for example Customer is 11 and Resource is 10. The full list of ParticipationTypeMask mappings can be found here.

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
adner1
  • 186
  • 6
  • 1
    You sir have saved the day and significant time that would have been spent investigating the relationships to the activity parties and service appointment. Thanks you very much for the short and precise answer! – Bojan Borisovski Aug 27 '13 at 09:11
  • Glad that you find it useful! – adner1 Aug 27 '13 at 11:49
  • @adner1 Thanks this was very useful info. I have a follow up question. Is it possible to filter your results against what is in the PartyList? – Comic Coder Nov 01 '13 at 12:26
  • No, I don't believe it is possible. As far as I know, filtering criteria can only be applied to the ServiceAppointmentSet, not to related related using $expand. See [here](http://stackoverflow.com/questions/9171310/odata-filter-with-items-in-a-expand) for more info. But as comments in the linked post suggest, the OData specification seems to support using filters on related entitites using a different notation than $expand, however I don't think that the CRM 2011 implementation supports this... – adner1 Nov 18 '13 at 07:44
1

Issues with capitalization tend to cause alot of OData errors. Also, have you tried creating your query in LinqPad (Assuming it is not CRM-Online)? I've found it quicker in generating my OData URLs.

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • Yes, i am aware of capitalization issues, but this is not it. As i have mentioned that the two party list fields Resources and Customers (these are their schema names), in Service Activity, are not returned as part of the ServiceAppointment object. I think the query for these fields might be related to another entity like AppointmentSet or maybe ActivityParty, i will continue digging. It is CRM Online environment the one i am working on but thanks for LinqPad, hadn't used it before, i will check it out. – Bojan Borisovski Aug 23 '13 at 15:41
  • Hi D! Have you ever used the syntax from the answer above yours, where the replier specified the guid for his *ServiceAppointment* in the parenthesis **before** the question mark? I value your input on this one. – Konrad Viltersten Aug 22 '14 at 20:57
  • 1
    Yes @KonradViltersten, I have used it like that. I believe it only works with the Guid, its just not what LinqPad spits out so I don't think I normally use it. – Daryl Aug 23 '14 at 00:59