Hi All,
The attached workflow working fine when mail send to one recipient. But when sending to multiple recipients it give me an error that “propertobjectcode” is cannot set to null.I have commented the below two lines where I have tried for multiple recipients. Need help on this.
Entity Fromparty = new Entity("activityparty");
Entity Toparty = new Entity("activityparty");
Fromparty["partyid"] = new EntityReference("systemuser", CreatedBy);
//EntityReferenceCollection sendTo = new EntityReferenceCollection();
bool bFlag = false;
foreach (var item in fetchResults.Entities)
{
bFlag = true;
if (item.Attributes.Contains("systemuserid"))
{
//sendTo.Add(new EntityReference("systemuser", new Guid(item.Attributes["systemuserid"].ToString())));
Toparty["partyid"] = new EntityReference("systemuser", new Guid(item.Attributes["systemuserid"].ToString()));
//Toparty.Attributes.Add("partyid", sendTo);
break;
}
}
if (bFlag)
{
//Toparty.Attributes.Add("partyid", sendTo);
Entity email = new Entity("email");
email["from"] = new Entity[] { Fromparty };
email["to"] = new Entity[] { Toparty };
email["directioncode"] = true;
Entity template = null;
if (Create.Get<bool>(executionContext))
{
template = GetTemplateByName("New Account Creation Mail to Data Admin", service);
}
if (Resubmit.Get<bool>(executionContext))
{
template = GetTemplateByName("Account Resubmit Mail", service);
}
if (template != null && template.Id != null)
{
var emailUsingTemplateReq = new SendEmailFromTemplateRequest
{
Target = email.ToEntity<Entity>(),
TemplateId = template.Id,
RegardingId = accountId,
RegardingType = "account"
};
var emailUsingTemplateResp = (SendEmailFromTemplateResponse)service.Execute(emailUsingTemplateReq);
}
}
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Yogesh Vijay Mulay