locked
CRM Create an activity party RRS feed

  • Question

  • Hi,

    I am trying to create a new phonecall activity and add activity party for the to and from. I have had this working in CRM 4.0 but i cannot make it work in CRM2011 I keep on getting the usefull error of

    "Value cannot be null.

    Parameter name: value"

    At first I was creating the phone call and the activity parties all in one command, but it was throwing an error, so I have narrowed it down just to the creation of the activity party. Here is the code I am trying to run. Crm is of type OrganizationServiceProxy.

     

                ActivityParty actParty = new ActivityParty();
                actParty.PartyId = new EntityReference();
                actParty.PartyId.Id = new Guid(m_sUserID);
                actParty.PartyId.LogicalName = SystemUser.EntityLogicalName;
                actParty.ParticipationTypeMask = new OptionSetValue(1);
                Crm.Create(actParty);
    


    Any help would be appreciated.

     

    Thanks,

    Giampaolo

    Monday, October 17, 2011 8:01 PM

Answers

  • I was only able to point out the obvious one. There seem to be more problems. 

    I just read the following blog post. 

    Based on your code, it looks like you are using the early bound entity classes, I am not sure at this moment how to apply the above fix to early bound XRM context object. 

    But I tried SDK approach, the following code worked for me. 

    using (var serviceProxy = new OrganizationServiceProxy(new Uri(crmServerUrl),
                                                                null,
                                                                null,
                                                                null))
    {
        serviceProxy.EnableProxyTypes();
    
        Entity phoneCall = new Entity("phonecall");
        phoneCall.Attributes.Add("subject", "New Call");
        phoneCall.Attributes.Add("phonenumber", "89646");
    
        phoneCall.Attributes.Add("ownerid", new EntityReference("systemuser", new Guid("CAC6A334-EFCC-E011-B633-001E37D06A04")));
        phoneCall.Attributes.Add("directioncode", true);
    
        phoneCall.Attributes.Add("regardingobjectid", new EntityReference("contact", new Guid("EBA69613-A6FA-E011-9CD4-CCB659E94CCA")));
    
        Entity actParty = new Entity("activityparty");
        actParty["partyid"] = new EntityReference("systemuser", new Guid("CAC6A334-EFCC-E011-B633-001E37D06A04"));
        phoneCall["to"] = new EntityCollection(new [] { actParty });
    
        serviceProxy.Create(phoneCall);
    }
    
     Hope this helps. 
    Daniel Cai | http://danielcai.blogspot.com | Tata Solutions Inc.
    Tuesday, October 25, 2011 3:19 AM

All replies

  • I don't think you would need to create an actual activity party record. 

    I am using a CRM letter record as example below. 

    ActivityParty actParty = new ActivityParty();
    actParty.PartyId = new EntityReference();
    actParty.PartyId.Id = new Guid(m_sUserID);
    actParty.PartyId.LogicalName = SystemUser.EntityLogicalName;
    actParty.ParticipationTypeMask = new OptionSetValue(1);
    
    var letter = new Letter
    {
    	Subject = "Sample Letter Activity",
    	ScheduledEnd = DateTime.Now + TimeSpan.FromDays(5),
    	Description = @"Blah, blah",
    	From = new ActivityParty[] { actParty},
    	To = new ActivityParty[] { toParty1, toParty2}
    };
    Hope this helps. 


    Daniel Cai | http://danielcai.blogspot.com | Tata Solutions Inc.
    • Proposed as answer by pogo69 Tuesday, October 18, 2011 4:42 AM
    Monday, October 17, 2011 10:24 PM
  • Hey I have noticed you didn't create the letter in your example? When i use all the same fields I get an error when creating a PhoneCall in my case (Same result if i change to Letter as well)

                Entity phoneCall = new Entity();
                phoneCall.LogicalName = PhoneCall.EntityLogicalName;
                phoneCall.Attributes.Add("subject","New Call");
                phoneCall.Attributes.Add("phonenumber", "89646");                                                
                phoneCall.Attributes.Add("ownerid",new EntityReference(SystemUser.EntityLogicalName, new Guid("1e49a79a-fc8d-de11-b665-000c297f1e4d")));
                phoneCall.Attributes.Add("directioncode", true);
                phoneCall.Attributes.Add("regardingobjectid", new EntityReference(Contact.EntityLogicalName, new Guid("d599ee36-c807-e011-86fe-0050569521c5")));
                ActivityParty actParty = new ActivityParty();
                actParty.PartyId = new EntityReference();
                actParty.PartyId.Id = new Guid("1E49A79A-FC8D-DE11-B665-000C297F1E4D");
                actParty.PartyId.LogicalName = SystemUser.EntityLogicalName;
                actParty.ParticipationTypeMask = new OptionSetValue(1);
                phoneCall.Attributes.Add("to" , new ActivityParty[] { actParty });
                Crm.Create(phoneCall);
    
    If i comment out the line "phoneCall.Attributes.Add("to" , new ActivityParty[] { actParty });" it creates the phone call no problem. Otherwise i get the same error message as originally posted. Any ideas?

    Tuesday, October 25, 2011 1:57 AM
  • I was only able to point out the obvious one. There seem to be more problems. 

    I just read the following blog post. 

    Based on your code, it looks like you are using the early bound entity classes, I am not sure at this moment how to apply the above fix to early bound XRM context object. 

    But I tried SDK approach, the following code worked for me. 

    using (var serviceProxy = new OrganizationServiceProxy(new Uri(crmServerUrl),
                                                                null,
                                                                null,
                                                                null))
    {
        serviceProxy.EnableProxyTypes();
    
        Entity phoneCall = new Entity("phonecall");
        phoneCall.Attributes.Add("subject", "New Call");
        phoneCall.Attributes.Add("phonenumber", "89646");
    
        phoneCall.Attributes.Add("ownerid", new EntityReference("systemuser", new Guid("CAC6A334-EFCC-E011-B633-001E37D06A04")));
        phoneCall.Attributes.Add("directioncode", true);
    
        phoneCall.Attributes.Add("regardingobjectid", new EntityReference("contact", new Guid("EBA69613-A6FA-E011-9CD4-CCB659E94CCA")));
    
        Entity actParty = new Entity("activityparty");
        actParty["partyid"] = new EntityReference("systemuser", new Guid("CAC6A334-EFCC-E011-B633-001E37D06A04"));
        phoneCall["to"] = new EntityCollection(new [] { actParty });
    
        serviceProxy.Create(phoneCall);
    }
    
     Hope this helps. 
    Daniel Cai | http://danielcai.blogspot.com | Tata Solutions Inc.
    Tuesday, October 25, 2011 3:19 AM
  • Thanks a lot for your help, CRM is crazy.
    Tuesday, October 25, 2011 3:30 AM