Showing posts with label CRM 2015. Show all posts
Showing posts with label CRM 2015. Show all posts

Apr 6, 2016

Read PartyList types and items

It is not to say that PartyList data type in Activities are the most complex ones in Dyanmics CRM. They can be called as multi-lookups of multi types. I had to play a bit to understand how I am going to identify item with specific entity type and do something. Though of sharing the code; in this example, I am checking the attendee list of appointment and see if I have Contact type to do something with those items.

EntityCollection _ReqAttendees = _appointmentContext.GetAttributeValue<EntityCollection>("requiredattendees");
if ((_ReqAttendees != null) && (_ReqAttendees.Entities.Count > 0))
{
  foreach (var _party in _ReqAttendees.Entities)
  {
    if (_party.GetAttributeValue<EntityReference>("partyid").LogicalName == "contact")
    {
       // Do the work 
       // Contact ID : _party.GetAttributeValue<EntityReference>("partyid").Id
       
    }
  }
}

Hope this is helpful.

Sep 21, 2015

Determine if Owner (SystemUser /Team) and assign to a record

In Dynamics CRM Owner can be either a user or a team. This can be little tricky when reading Owner from a record and set to another one.

Please check below screen shot of Account. You can simply check this with OwnerIdType, yet you can’t retrieve that field for some reason.

 
Still we can check two different fields that holds Either User Id or team Id.

In fact, I tried below approach which worked for me.

String OwningEntityType = String.Empty;
if (_account.OwningTeam != null)
{
    OwningEntityType = "team";
}
else
{
    OwningEntityType = "systemuser";
}

AssignRequest assignAcc = new AssignRequest
{
     Assignee = new EntityReference(OwningEntityType, _account.OwnerId.Id),
     Target = new EntityReference(<Target Entity Name>, <Target Entity Name ID>)
};
organizationService.Execute(assignAcc);