In an earlier Blog I covered creating activities, but did not cover the activityparty in depth. Each activity has a number of activityparty arrays containing lookups to the CRM systemuser, contact, lead, and account entities that are involved in that activity.
For many purposes the only attributes that need to be set in each ActivityParty are the participationtypemask and partyid. The name participationtypemask is a little misleading since it needs to be set to a picklist with a value from the ActivityPartyType rather than actually being a bitmask like the SecurityPrincipal AccessMask.
There are numerous ActivityPartyTypes used for the different ActivityParty arrays in each activity. A complete list of these types is located here MSDN ActivityPartyType Class. The partyid is just a lookup to the appropriate systemuser, contact, lead or account.
Typically when importing activities you will be matching against an email address and/or contact or lead name. I'd included some example code that will creates an activityparty array for use in creating an activity based on email addresses. A few examples of how I would call this are the following:
thisEmail.to = CreateActivityParty(to_rfc882, ActivityPartyType.ToRecipient);
thisEmail.from = CreateActivityParty(from_rfc882, ActivityPartyType.Sender);
thisEmail.cc = CreateActivityParty(cc_rfc882, ActivityPartyType.CcRecipient);
thisEmail.bcc = CreateActivityParty(bcc_rfc882, ActivityPartyType.BccRecipient);
This shows an email entity having a number of attributes assigned an appropriate activityparty array.
This code takes the emailAddresses string from a given email and creates a list of email addresses that will be part of the ActivityParty array. Then it looks for a match for each email address against systemusers, contacts, leads and finally accounts. Notice that an ActivityParty array can consist of any combination of these entities.
If you have any questions please let me know.