Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create ActivityParty in CRM without early bound Entities

As a requirement I cannot use the early bound context created with "CrmSvcUtil". The problem is that a new phonecall activity expects two fields ('from' and 'to') which are Entities of type activityparty. The standard XRM/CRM namespace does not contain a class similar to ActivityParty created with the Utility.

I tried filling it with an EntityCollection but then the field will be empty. Next I tried to recreate the structure of a working phonecall activity. EntityCollection "activityparty" -> with one Entity "activityparty" -> with EntityReference attribute "partyid" -> the entity ref (e.g. "contact" and the contact's id). But it simply does not work.

How can I create an ActivityParty (or better a phonecall Activity) with the "normal" Entitiy classes?

like image 878
Kirschi Avatar asked Apr 30 '14 13:04

Kirschi


2 Answers

If I'm right you don't need to use an EntityCollection but an array of Entity

To create a phone call with late bound syntax will be:

Entity from1 = new Entity("activityparty");
Entity to1 = new Entity("activityparty");
Entity to2 = new Entity("activityparty"); // two contacts inside the to field

from1["partyid"]= new EntityReference("systemuser", userId);
to1["partyid"]= new EntityReference("contact", contact1Id);
to2["partyid"]= new EntityReference("contact", contact2Id);

Entity phonecall = new Entity("phonecall");

phonecall["from"] = new Entity[] { from1 };
phonecall["to"] = new Entity[] { to1, to2 };
// other phonecall fields

Guid phonecallId = service.Create(phonecall);
like image 146
Guido Preite Avatar answered Nov 19 '22 19:11

Guido Preite


Even though I upvoted the answer but I had simmilar problem with serialization of ActivityParty. I came to solution that doesn't require you to give up on early bound entities.

what you need to do is something like this:

IEnumerable<ActivityParty> party = new [] { new ActivityParty { PartyId="", EntityLogicalName="..." } }; 
phonecall["to"] = new EntityCollection(party.Select(x => x.ToEntity<Entity>).ToList());

(I didn't test the code and wrote it from the air but you should feel the idea)

like image 43
TrN Avatar answered Nov 19 '22 19:11

TrN