4

I want to send a notification email after creating a contact in CRM.

For that I have written the following code.. but it is throwing an exception of "Invalid Party object type 9". I searched for it but could't find reasonable help

Thanks

code :

  //Defining Activity Parties (starts)
  Entity Fromparty = new Entity("activityparty");
  Entity Toparty = new Entity("activityparty");

  //set partyid
  Toparty["partyid"] = new EntityReference("contact", ContactGuid.Id);
  Fromparty["partyid"] = new EntityReference("team", ConsumerTeam.Id);

  //create email entity
  Entity Email = new Entity("email");
  Email["from"] = new Entity[] { Fromparty };
  Email["to"] = new Entity[] { Toparty };
  Email["subject"] = "Account Login Information";
  Email["description"] = PopulateBody(UserName,Password);
  Email["directioncode"] = true;
  Email["regardingobjectid"] = new EntityReference("contact", ContactGuid.Id);
  Guid EmailID = Service.Create(Email);

  //Sending email
  SendEmailRequest reqSendEmail = new SendEmailRequest();
  reqSendEmail.EmailId = EmailID;//ID of created mail
  reqSendEmail.TrackingToken = "";
  reqSendEmail.IssueSend = true;
  SendEmailResponse res = (SendEmailResponse)Common.Common.Execute(reqSendEmail);
jcjr
  • 1,503
  • 24
  • 40
mzh
  • 515
  • 8
  • 21

1 Answers1

13

You are trying to set the from attribute of an Email entity to a Team. This is not possible because the from attribute can be only a user or a queue:

enter image description here

You get Invalid Party object type 9 because 9 is the entitycode for team entity.

Change your code in order to set the from to be a user or a queue record.

Guido Preite
  • 14,905
  • 4
  • 36
  • 65
  • Guido : thanks it worked........... i would definitely suggest this answer but unfortunately don't have points :p – mzh Dec 06 '14 at 10:44
  • i would definitely marked it as answered ... but unable now because of less reputations in stackoverflow – mzh Dec 16 '14 at 05:19