CRM 2016 – ActivityParty and ActivityParty Lists

To code simply you must master complexity and break it down to it’s simpliest form #HoskCodeWisdom

Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it. Alan Perlis

Junior developers create many lines of code and complexity, senior developers then remove lines of code and simplify #HoskCodeWisdom 

The ActivityParty entity catches many new Dynamics 365/CRM developers by surprise because it’s an entity inside an entity.  This blog post looks at ActivityParty and some great resources to help you conquer it.

To spice up CRM development Microsoft likes to throw in a few special entities that have special powers.  Microsoft have created great documentation but then littered it around so it’s hard to piece all the useful bits together.

There are special non standard entities lurking in CRM, this can catch out new developers because they are not standard, they can also annoy some people because we can’t make them
  • Customers (which can hold accounts and contacts)
  • ActivityParty (can hold any of the activity types)
  • regarding (can hold any object)
  • Owner – it can be a user or a team
  • Address entity, it’s half on the account, contact form but you can see it in advanced finds

I got an odd error once with ActivityParty and casting

The ActivityParty is complex record,  its important to understand how it’s linked to Activities,  Microsoft have some excellent documentation here

http://msdn.microsoft.com/en-us/library/gg309626.aspx

This picture quickly summaries ActivityParty

Richard Knudson has a great blog post on ActivityParties

 

First step go to the MDSN definition

http://msdn.microsoft.com/en-us/library/gg328549.aspx

An activity party represents a person or group associated with an activity. An activity can have multiple activity parties.

Where are party lists used?  The most common area in CRM Activity Party is used is the To and From on an email.   The reason the ActivityParty is used is because an email can have multiple email addresses in the TO, CC (it’s a party of people)

Email is a easy way to understand not only how Activity Lists work but why we need them.  The TO field on an email might contain multiple email addresses.  

It also explains the name, each person on an email is an activity party and an activity party is a person or group.

As mentioned before an ActivityParty entity can hold many different entities, to see what type it is you need to check the Activity Party Type

There are 11 activity party types in Microsoft Dynamics 365. The different types are identified by the a different int value as shown below from MSDN documentation.

Activity party type Value Description
Sender 1 Specifies the sender.
ToRecipient 2 Specifies the recipient in the To field.
CCRecipient 3 Specifies the recipient in the Cc field.
BccRecipient 4 Specifies the recipient in the Bcc field.
RequiredAttendee 5 Specifies a required attendee.
OptionalAttendee 6 Specifies an optional attendee.
Organizer 7 Specifies the activity organizer.
Regarding 8 Specifies the regarding item.
Owner 9 Specifies the activity owner.
Resource 10 Specifies a resource.
Customer 11 Specifies a customer.
From the list above the ActivityParty is used with activities –
  • emails
  • appointments
  • phone calls
  • letters
  • faxes.
Not all of the Activity Party types can be used with all all the activities.  e.g. appointments have Organizers, OptionalAttendee, RequiredAttendee but this wouldn’t work with emails.

The following table lists the activity party types that are supported for each activity, and the corresponding activity properties to specify those activity party types. ActivityParty entity

Activity entity name Supported activity party type Activity attribute
Appointment OptionalAttendee
Organizer
RequiredAttendee
Appointment.OptionalAttendees
Appointment.Organizer
Appointment.RequiredAttendees
CampaignActivity Partner
Sender
CampaignActivity.Partners
CampaignActivity.From
CampaignResponse Customer
Partner
From
CampaignResponse.Customer
CampaignResponse.Partner
CampaignResponse.From
Email BccRecipient
CcRecipient
Sender
ToRecipient
Email.Bcc
Email.Cc
Email.From
Email.To
Fax Sender
ToRecipient
Fax.From
Fax.To
Letter BccRecipient
Sender
ToRecipient
Letter.Bcc
Letter.From
Letter.To
PhoneCall Sender
ToRecipient
PhoneCall.From
PhoneCall.To
RecurringAppointmentMaster OptionalAttendee
Organizer
RequiredAttendee
RecurringAppointmentMaster.OptionalAttendees
RecurringAppointmentMaster.Organizer
RecurringAppointmentMaster.RequiredAttendees
ServiceAppointment Customer
Resource
ServiceAppointment.Customers
ServiceAppointment.Resources

Reading a Resource

In this example I will be reading the resources value
 
ServiceAppointment.resources can hold multiple resources
 
the field value is IENumberable but I like to convert it into a list

List<ActivityParty> resources = (List<ActivityParty >)serviceAppointment.Resources.ToList();

On the front end resources can contains users or Facility/equipment.  For those of you haven’t used the scheduling side of Microsoft (I only know about it because you are tested on it for the applications certification and it has been useful to understand how it works as potential customers have asked about it)
 
in my example, if want to display some details about the facilities/equipment and ignore people (they don’t have exciting details!)
 
So after capturing the resources in 
 
The participationTypeMask = 10, which is a resource.
 
There are two guids, ID’s
ActivityPartyId
 
PartyId
 
The ActivityPartyID is the guid of the ActivityParty, the PartyID is the guid of the resource selected (e.g. user or facility/equipment).  
 
In my code I want to check the PartyID, see if it’s a piece of equipment (not user) and if it is lookup the details for 
For an in depth example go to
Some more useful information can be found in the links below

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s