CRM-向子网格中的联系人发送电子邮件 [英] CRM - sending email to contacts in sub grid

查看:90
本文介绍了CRM-向子网格中的联系人发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为慈善机构工作,我们希望使用Dynamics 365支持我们的筹款团队。我们创建了一个与联系人实体具有N:N关系的``筹款活动''实体(在组织中重命名为``个人''。我在每个实体上都有一个子网格,以便我们可以从联系人记录中将联系人添加到事件中
我们需要能够向活动注册的每个人发送电子邮件,以祝他们在活动前好运。我创建了一个针对筹款活动实体的工作流,该工作流应在活动开始前7天运行事件开始日期,但是当我对此进行测试时,系统作业显示错误;需要注意;当我查看该过程时,它显示消息:电子邮件必须至少具有一个收件人,然后才能发送。
处理错误图片
在WF发送电子邮件属性中,我尝试过使用我在TO字段中可用的列表中的``联系人''和``命名联系人(查找)''(但见下面的屏幕截图),但是两个选项的结果相同。
到行选项列表图像
我的测试事件有2个与之链接的个人(联系人)而且我可以在事件记录的子网格中看到它们,但是似乎无法向他们发送电子邮件。
以下是失败进程的详细信息:

I work for a charity and we want to use our Dynamics 365 to support our fundraising team.  We have created a 'Fundraising Event' entity with an N:N relationship to the Contact entity (renamed to 'Individual' in our Org.  I have a sub grid on each entity so that we can add contacts to events either from the Contact record or from the event record. We need to be able to send emails to everyone registered for an event to wish them good luck before the event.  I have created a workflow against the 'Fundraising Event' entity to run 7 days before an event start date however when I an testing this the System job shows "Error; Needs Attention" and when I look at the process it shows a message "The email must have at least one recipient before it can be sent." Process error image In the WF send email properties, I have tried using 'Contact' and 'Named Contact(Lookup)' from the list I have available (see screen shot below) in the TO field but I get the same result with both options. To line option list image My test event has 2 Individuals (Contacts) linked to it and I can see them both in the sub grid on the event record but I can't seem to be able to send emails to them. Here are the details from a failed process:

Plugin Trace:
[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.SendEmail]
[SendEmailStep1]
Error Message:
Unhandled Exception:
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The e-mail must have at least one recipient before it can be sentDetail: 

<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">

<ActivityId>9161cfb2-308e-4b19-af39-b859a78f132f</ActivityId>

<ErrorCode>-2147218684</ErrorCode>

<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />

<Message>The e-mail must have at least one recipient before it can be sent</Message>

<Timestamp>2017-03-31T11:07:27.6562583Z</Timestamp>

<ExceptionSource i:nil="true" />

<InnerFault>

<ActivityId>9161cfb2-308e-4b19-af39-b859a78f132f</ActivityId>

<ErrorCode>-2147218684</ErrorCode>

<ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />

<Message>The e-mail must have at least one recipient before it can be sent</Message>

<Timestamp>2017-03-31T11:07:27.6562583Z</Timestamp>

<ExceptionSource i:nil="true" />

<InnerFault i:nil="true" />

<OriginalException i:nil="true" />

<TraceText i:nil="true" />

</InnerFault>

<OriginalException i:nil="true" />

<TraceText>[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.SendEmail]

[SendEmailStep1]

</TraceText>

</OrganizationServiceFault>

at Microsoft.Crm.Workflow.Services.SendEmailActivityService.Execute(ActivityContext executionContext, SendEmail sendEmail)

at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)

at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

是否可以执行我尝试使用的即用型功能?如果是这样,我想念什么?
谢谢,
保罗

Is it possible to do what I'm attempting using out of the box functionality? If so, what am I missing? Thanks, Paul

推荐答案

我们做了类似的事情。

在电子邮件的预操作中注册插件创建消息&

Register a plugin in Pre-operation of Email Create message & have this logic in there.

这会将N:N联系人相交实体的收件人添加到电子邮件列表中

This will add the recipients from N:N contact intersect entity in email To list.

    ConditionExpression frCondition1 = new ConditionExpression();
    ConditionExpression frCondition2 = new ConditionExpression();
    EntityCollection frResponse = new EntityCollection();
    EntityCollection toOwner = new EntityCollection();

    toOwner = targetEntity.GetAttributeValue<EntityCollection>("to");

    frCondition1 = CreateConditionExpression("parentIdcolummn", ConditionOperator.Equal, new string[] { parent.Id.ToString() });
    frCondition2 = CreateConditionExpression(statuscode, ConditionOperator.Equal, new object[] { 1 });

    ConditionExpression[] conditions = new ConditionExpression[] { frCondition1, frCondition2 };

    FilterExpression filterExpression = new FilterExpression();

filterExpression.Conditions.AddRange(conditions);
filterExpression.FilterOperator = LogicalOperator.And;

QueryExpression queryExpression = new QueryExpression();
queryExpression.ColumnSet = GenerateColumnSet("columnNames");
queryExpression.EntityName = "entityName";
queryExpression.Criteria = filterExpression;
queryExpression.NoLock = true;

    frResponse =  (EntityCollection)service.RetrieveMultiple(queryExpression);

    if(frResponse != null && frResponse.Entities.Count > 0)
    {
        //Adding all FRs in the email
        foreach (Entity FilingRep in frResponse.Entities)
        {
            Guid frGuid = ((EntityReference)FilingRep["contactLookupfieldname"]).Id;

            Entity toParty = new Entity("activityparty");

            toParty[ActivityParty.ActivityPartId] = new EntityReference("contact", frGuid);

            ToOwner.Entities.Add(toParty);
        }
    }

    targetEntity[EmailEntityAttributeName.To] = toOwner;

这篇关于CRM-向子网格中的联系人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆