Hi All,
I am trying to create an email message and also to list that email under Activities on Case form. But I get the error that "Regardingobjecttypecode cannot be null when regardingobjectid is not null" . Can anyone tell me how to set regardingobjecttypecode and how to list the email activity under Activities. Here's the code :
Entity emailTemplateInstance = ((EntityCollection)instTemplateResp.Results["EntityCollection"])[0];
emailTemplateInstance.Attributes["subject"] = ((EntityCollection)instTemplateResp.Results["EntityCollection"])[0].GetAttributeValue<string>("subject");
emailTemplateInstance.Attributes["description"] = emailTemplateInstance.Attributes["description"].ToString().Replace("%7bCaseNumber%7d", caseNumber);
Entity email = new Entity("email");
Entity senderParty = new Entity("activityparty");
Entity receiverParty = new Entity("activityparty");
receiverParty["partyid"] = new EntityReference("contact", emailReceiversId);
senderParty["partyid"] = new EntityReference("systemuser", emailSendersId);
Entity[] emailReceivers = { receiverParty };
Entity[] emailSenders = { senderParty };
email["to"] = emailReceivers;
email["from"] = emailSenders;
email["subject"] = emailTemplateInstance.Attributes["subject"];
email["description"] = emailTemplateInstance.Attributes["description"];
email["regardingobjectid"] = new EntityReference("case", caseId);
Guid emailId = service.Create(email);
SendEmailRequest sendEmailreq = new SendEmailRequest
{
EmailId = emailId,
TrackingToken = "",
IssueSend = true
};
SendEmailResponse sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);
*This post is locked for comments