creating ActivityParties from Silverlight

Unanswered creating ActivityParties from Silverlight

  • Friday, April 27, 2012 1:43 PM
     
      Has Code

    I am trying to create ActivityParty records in CRM2011 from Silverlight. Although ContactIds list contains 13 items, just one ActivityParty is created.

    Here's my code:

        private void CreateActivityParties(Appointment Activity, List<Guid> ContactIds)
        {
          try
          {
            foreach (var ContactID in ContactIds)
            {
              ActivityParty APReq = new ActivityParty();
    
              WoodContext.EntityReference AppointmentReference = new WoodContext.EntityReference();
              AppointmentReference.LogicalName = "appointment";
              AppointmentReference.Id = Activity.ActivityId;
              
              APReq.ActivityId = AppointmentReference;
              APReq.PartyId = new WoodContext.EntityReference() { Id = ContactID, LogicalName = "contact" };
    
              APReq.InstanceTypeCode = new WoodContext.OptionSetValue();
              APReq.InstanceTypeCode.Value = 0;
              APReq.IsPartyDeleted = false;
              APReq.ParticipationTypeMask = new WoodContext.OptionSetValue();
              APReq.ParticipationTypeMask.Value = 5;
    
              _context.AddToActivityPartySet(APReq);
    
            }
            _context.BeginSaveChanges(OnCreateAPComplete, Activity);
          }
          catch (SystemException ex)
          {
            LogHelper.AddError("InterfActivity(CreateActivityParties): " + ex.InnerException);
          }
        }

    any suggestions?

    Thanks!


All Replies

  • Friday, April 27, 2012 2:37 PM
     
     

    it could be becuase you are not adding all activity parties properly.. I have done some chnages in your code above for the same..

    please try following code and see if this works..

    private void CreateActivityParties(Appointment Activity, List<Guid> ContactIds)
       
    {
         
    try
         
    {

              WoodContext.EntityReference AppointmentReference = new WoodContext.EntityReference();
             
    AppointmentReference.LogicalName = "appointment";
             
    AppointmentReference.Id = Activity.ActivityId;

              ActivityParty APReq = null;       
           foreach (var ContactID in ContactIds)
           
    {
             
    APReq = new ActivityParty();
          

               APReq.ActivityId = AppointmentReference;
             
    APReq.PartyId = new WoodContext.EntityReference() { Id = ContactID, LogicalName = "contact" };

             
    APReq.InstanceTypeCode = new WoodContext.OptionSetValue();
             
    APReq.InstanceTypeCode.Value = 0;
             
    APReq.IsPartyDeleted = false;
             
    APReq.ParticipationTypeMask = new WoodContext.OptionSetValue();
             
    APReq.ParticipationTypeMask.Value = 5;

              _context
    .AddToActivityPartySet(APReq);

           
    }
            _context
    .BeginSaveChanges(OnCreateAPComplete, Activity);
         
    }
         
    catch (SystemException ex)
         
    {
           
    LogHelper.AddError("InterfActivity(CreateActivityParties): " + ex.InnerException);
         
    }
       
    }


    MayankP
    My Blog
    Follow Me on Twitter

  • Friday, April 27, 2012 7:04 PM
     
     
    To create multiple ActivityParty you need to make an array of ActivityParty.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!

  • Saturday, April 28, 2012 4:45 AM
     
     

    MayankP, your optimalization of the code seems good; however, it doesn’t solve my problem = still only one ActivityParty is created (checked in db)

  • Saturday, April 28, 2012 4:45 AM
     
     

    Mubasher, I am not able to create an array of ActivityParty in Silverlight REST. Or, is there some way to do it?


    • Edited by Jiri Cabal Saturday, April 28, 2012 4:45 AM
    •  
  • Saturday, April 28, 2012 7:56 AM
     
      Has Code
    You could use ActivityParty Array Like below code
                ActivityParty party = new ActivityParty
                {
                    PartyId = new EntityReference(SystemUser.EntityLogicalName, _ContactId)
                };
                ActivityParty party2 = new ActivityParty
                {
                    PartyId = new EntityReference(SystemUser.EntityLogicalName, _ContactId)
                };
    // Create the fax object.
                Fax fax = new Fax
                {
                    Subject = "Sample Fax",
                    From = new ActivityParty[] { party,party2 },
                    
                };
    
                



    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!


    • Edited by MubasherSharif Saturday, April 28, 2012 7:57 AM
    • Proposed As Answer by MubasherSharif Sunday, April 29, 2012 1:20 PM
    • Unproposed As Answer by Jiri Cabal Sunday, April 29, 2012 7:36 PM
    •  
  • Sunday, April 29, 2012 7:36 PM
     
     

    Unfortunately, the class Fax doesn’t have property From in Silverlight.

    Probably, I wasn’t clear enough: I am looking for a solution working with Silverlight REST similarly to my piece of code.