Thursday, April 15, 2010

ActivityParty Property

The Properties of a DynamicEntity can be confusing at first but are pretty straightforward after you get the hang of it.  However, one property that can be hard to figure out is the ActivityParty.  It is actually an array of DynamicEntity and each DynamicEntity in that array has a Lookup property called "partyid".  Here's a code snippet for retrieving the "to" from an activity DynamicEntity in a plugin.

Note:  This snippet is just finding the first record in the To attribute.

DynamicEntity activity = (DynamicEntity)context.InputParameters.Properties["Target"];
if (activity.Properties.Contains("to"))
{
     DynamicEntity[] to = (DynamicEntity[])activity.Properties["to"];
     if (to.Count() > 0 && to[0].Properties.Contains("partyid"))
     {
          Lookup partyId = (Lookup)to[0].Properties["partyid"];
          // Run logic
     }
}

2 comments:

  1. Hi Blake,

    smart solution. I try to use the "partyid" to use it ase a value in another lookup (want to write in at "create"). Unfortunatily the conversion of the "partyid" into the required guid type das not work. Do have an Idea how to get it work?

    DynamicEntity[] to = (DynamicEntity[])activity.Properties["to"];
    if (to.Count() > 0 && to[0].Properties.Contains("partyid"))
    {
    Lookup partyId = (Lookup)to[0].Properties["partyid"];

    Lookup RegardingContact = new Lookup();
    RegardingContact.type = EntityName.contact.ToString();
    RegardingContact.Value = new Guid(partyId.Value.ToString());


    LookupProperty RegardCont = new LookupProperty("crm1_regardingcontactid", RegardingContact);
    entity.Properties.Add(RegardCont);

    ReplyDelete
  2. Flows

    Are you sure the Guid value of partyId is a contact Id?

    ReplyDelete