Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Unable to create an Email and relate an Activity Party from Silverlight Application

$
0
0

Hi,

I am trying to create a new email record (which I am able to create) and set the current user as the sender (having problems achieving this). I get a System.Data.Services.Client.DataServiceRequestException which says that "An error occurred while processing this request." I get the exception at the second _context.EndSaveChanges(result) (The callback function when the Activity Party is saved).

What is the correct way of relating an Email and an Activity Party?

Here's the code I'm using.

privatevoid SendEmail_Click(Object sender, RoutedEventArgs e)
    {
      Email newEmail = new Email();
      newEmail.ActivityId = Guid.NewGuid();
      newEmail.Subject = "Silverlight E-mail";
      newEmail.Description = "This e-mail was created from Silverlight";
      _context.AddToEmailSet(newEmail);
      _context.BeginSaveChanges(EmailSaved, newEmail);
    }privatevoid EmailSaved(IAsyncResult result)
    {
      _context.EndSaveChanges(result);
      Email createdEmail = result.AsyncState as Email;
      oEmail = createdEmail; //oEmail is a global variable that stores the created e-mail
      ActivityParty ap = new ActivityParty();
      ap.ActivityPartyId = Guid.NewGuid();/*
       * ActivityId Reference
       * */
      EntityReference emailReference = new EntityReference();
      emailReference.LogicalName = "email";
      emailReference.Id = new Guid(this.getUserId());
      ap.ActivityId = emailReference;/*
       * Party ID Reference
       * */
      EntityReference oUserReference = new EntityReference();
      oUserReference.Id = new Guid(this.getUserId());
      oUserReference.LogicalName = "systemuser";
      ap.PartyId = oUserReference;/**
       * Other values
       */
      ap.InstanceTypeCode = new OptionSetValue();
      ap.InstanceTypeCode.Value = 0;
      ap.IsPartyDeleted = false;
      ap.ParticipationTypeMask = new OptionSetValue();
      ap.ParticipationTypeMask.Value = 1; //SENDER 
      _context.AddToActivityPartySet(ap);
      _context.BeginSaveChanges(APSaved,ap);
    }privatevoid APSaved(IAsyncResult result)
    {
      _context.EndSaveChanges(result); // I GET AN ERROR HERE
      ActivityParty ap = result.AsyncState as ActivityParty;
    }

Thanks in advance


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>