Search code examples
dynamics-crmdynamics-365

How to create record for Phonecall Activity in Dynamics CRM 365 for 'CallFrom' and 'CallTo'


`if (!string.IsNullOrEmpty(phonecall.From))
phonecallEntity.Attributes.Add("from", new EntityReference("systemuser", new 
Guid(phonecall.From)));
if (!string.IsNullOrEmpty(phonecall.To))
phonecallEntity.Attributes.Add("to", new EntityReference("contact", new 
Guid(phonecall.To)));

I'm trying to set the from and to field on a Phone Call activity in Dynamics 365. I'm using the following code but the to and from fields are empty when creating a Phone Call. What do I need to change?


Solution

  • The to and from fields on Activity entities (line Phone Call) expect an EntityCollection, not an EntityReference as you are trying to pass them.

    Each entity within your EntityCollection should be an ActivityParty linked to an EntityReference:

    // Create your collection.
    var collection = new EntityCollection();
    
    // Create your parties; one party per reference (to/from).
    var party1 = new Entity("activityparty");
    party["partyid"] = new EntityReference(logicalName, id);
    
    
    // Add your parties to your collection.
    collection.Entities.Add(party1);
    
    // Set your to phone call's to field.
    phoneCallEntity["to"] = collection;