Dynamics 365 Marketing自定义渠道的步骤
Dynamics 365 Marketing 创建自定义渠道:大家知道,微软官方文档,也有很具体的介绍,但是大家发现按照微软的官方介绍,少不了跳坑,这里给大家整理分享一些。
微软官方介绍:https://learn.microsoft.com/zh-cn/dynamics365/customer-insights/journeys/real-time-marketing-extend-outreach-custom-channels
1.创建2个实体:渠道【new_flashinfosmschannel】、消息模板【new_flashinfosmschannel_message】
new_flashinfosmschannel保存账号账号秘钥信息,new_flashinfosmschannel_message包含new_text和new_placeholders字段
注意:如果想用标准消息模板,可以不用创建消息模板实体,这样就无法扩展字段,这里建议用自己创建的
标准消息模板效果:
2.导出解决方案,往XML增加一个关系【EntityRelationship】
注意:导出的解决方案,需要包含3个实体【msdyn_channelinstance】【new_flashinfosmschannel】【new_flashinfosmschannel_message】
示例:
<EntityRelationship Name="msdyn_ChannelInstance_extendedentityid_new_flashinfosmschannel"> <EntityRelationshipType>OneToMany</EntityRelationshipType> <IsCustomizable>0</IsCustomizable> <IntroducedVersion>1.0.0.0</IntroducedVersion> <IsHierarchical>0</IsHierarchical> <ReferencingEntityName>msdyn_ChannelInstance</ReferencingEntityName> <ReferencedEntityName>new_flashinfosmschannel</ReferencedEntityName> <CascadeAssign>NoCascade</CascadeAssign> <CascadeDelete>RemoveLink</CascadeDelete> <CascadeReparent>NoCascade</CascadeReparent> <CascadeShare>NoCascade</CascadeShare> <CascadeUnshare>NoCascade</CascadeUnshare> <CascadeRollupView>NoCascade</CascadeRollupView> <IsValidForAdvancedFind>1</IsValidForAdvancedFind> <ReferencingAttributeName>msdyn_extendedentityId</ReferencingAttributeName> <RelationshipDescription> <Descriptions> <Description description="" languagecode="1033" /> </Descriptions> </RelationshipDescription> <EntityRelationshipRoles> <EntityRelationshipRole> <NavPaneDisplayOption>UseCollectionName</NavPaneDisplayOption> <NavPaneArea>Details</NavPaneArea> <NavPaneOrder>10000</NavPaneOrder> <NavigationPropertyName>msdyn_extendedentityid_new_flashinfosmschannel</NavigationPropertyName> <RelationshipRoleType>1</RelationshipRoleType> </EntityRelationshipRole> <EntityRelationshipRole> <NavigationPropertyName>msdyn_ChannelInstance_extendedentityid_new_flashinfosmschannel</NavigationPropertyName> <RelationshipRoleType>0</RelationshipRoleType> </EntityRelationshipRole> </EntityRelationshipRoles> </EntityRelationship>
3.写插件代码&注册上去&在CRM创建customer api,比如创建的new_flashinfosms_customapi
注意:此处有坑。出入参必须是payload和response,类型可以是String
4.在代码创建自定义渠道,下面的代码,可以用控制台运行,当然大家要先获取组织服务。
/// <summary> /// 渠道定义 /// </summary> /// <param name="service"></param> /// <returns></returns> public static Guid Insert_msdyn_channeldefinitions(IOrganizationService service) { Entity entity = new Entity("msdyn_channeldefinition"); entity.Id = Guid.NewGuid();// entity["msdyn_name"] = "Flashinfo SMS Channel"; entity["msdyn_displayname"] = "Flashinfo SMS Channel"; entity["msdyn_description"] = "Flashinfo SMS Channel"; entity["msdyn_channeltype"] = "Custom"; entity["msdyn_outboundendpointurltemplate"] = "/new_flashinfosms_customapi"; entity["msdyn_hasinbound"] = false; entity["msdyn_hasdeliveryreceipt"] = true; entity["msdyn_supportsaccount"] = false; entity["msdyn_channeldefinitionexternalentity"] = "new_flashinfosmschannel"; entity["msdyn_channeldefinitionexternalformid"] = "2054e3cb-e2fb-4d0a-bdde-cc51982da65d"; //必须小写,是实体new_flashinfosmschannel的主窗体ID entity["msdyn_messageformid"] = "9af480f8-a1b8-422a-9e4e-62d95a952ccf"; //必须小写,可以为null,代表使用标准模板效果 var id = service.Create(entity); return id; } /// <summary> /// 消息定义 /// </summary> /// <param name="service"></param> /// <param name="cid"></param> public static void Insert_msdyn_channelmessageparts(IOrganizationService service, Guid cid) { Entity entity = new Entity("msdyn_channelmessagepart"); entity.Id = Guid.NewGuid();// entity["msdyn_name"] = "text";// 消息部分的名称 entity["msdyn_displayname"] = "text";// 显示名称 entity["msdyn_description"] = "text";// 说明 entity["msdyn_channeldefinitionid"] = new EntityReference("msdyn_channeldefinition", cid);// 渠道定义 ID entity["msdyn_type"] = new OptionSetValue(192350000);// 渠道类型 entity["msdyn_isrequired"] = true;// 指示是否需要此部分 entity["msdyn_maxlength"] = 1000;// 部分的最大长度 var id = service.Create(entity); }
调用:
var id = Insert_msdyn_channeldefinitions(adminService); Insert_msdyn_channelmessageparts(adminService, id);
5.在自定义渠道,就能看到新增的渠道
6.调整消息模板new_flashinfosmschannel_message的主窗体formxml
FormXML和控件代码的位置:
调整消息模板new_flashinfosmschannel_message的主窗体formxml:
..
<formid>{69723cfe-3835-4126-ab9a-a82a5b88c21d}</formid>
<form>
<tabs>
<tab verticallayout="true" id="{921c575b-3e4a-495c-867d-b8f6e1c113e0}" IsUserDefined="1">
<labels>
<label description="General" languagecode="1033" />
</labels>
<columns>
<column width="100%">
<sections>
<section showlabel="false" showbar="false" IsUserDefined="0" id="{661ec403-bf06-41a0-86de-f93a05c558f6}">
<labels>
<label description="General" languagecode="1033" />
</labels>
<rows>
<row>
<cell id="{95b0236e-63bd-c6ea-52dc-d7b9c4dca696}" showlabel="true" locklevel="0">
<labels>
<label description="Text" languagecode="1033" />
</labels>
<control id="cr65f_text" classid="{F9A8A302-114E-466A-B582-6771B2AE0D92}" datafieldname="cr65f_text" disabled="false" uniqueid="{05bb6ed1-e802-412c-9813-7eded53f3f73}" />
</cell>
</row>
<row>
<cell id="{dc3b7ed4-9a3d-14e1-ac32-b851ea4e11c3}" showlabel="true" locklevel="0" visible="false">
<labels>
<label description="Placeholders" languagecode="1033" />
</labels>
<control id="cr65f_placeholders" classid="{E0DECE4B-6FC8-4a8f-A065-082708572369}" datafieldname="cr65f_placeholders" disabled="false" uniqueid="{b02dc4a0-7711-0a2a-0ce4-d0c384a17712}" />
</cell>
</row>
</rows>
</section>
</sections>
</column>
</columns>
</tab>
</tabs>
..
</form>
..
窗体Form代码在微软文档的位置:
在form里面,需要增加空间标签,示例:
<controlDescriptions> <controlDescription forControl="{05bb6ed1-e802-412c-9813-7eded53f3f73}"> <customControl formFactor="0" name="MsdynmktControls.RichTextControl.RichTextControl"> <parameters> <value>cr65f_text</value> <emojiPickerEnabled static="true" type="Enum">false</emojiPickerEnabled> <isSingleLine static="true" type="Enum">false</isSingleLine> <personalizationEnabled static="true" type="Enum">true</personalizationEnabled> <personalizationPlaceholders>cr65f_placeholders</personalizationPlaceholders> <inlinedActionsBar static="true" type="Enum">true</inlinedActionsBar> </parameters> </customControl> <customControl formFactor="1" name="MsdynmktControls.RichTextControl.RichTextControl"> <parameters> <value>cr65f_text</value> <emojiPickerEnabled static="true" type="Enum">false</emojiPickerEnabled> <isSingleLine static="true" type="Enum">false</isSingleLine> <personalizationEnabled static="true" type="Enum">true</personalizationEnabled> <personalizationPlaceholders>cr65f_placeholders</personalizationPlaceholders> <inlinedActionsBar static="true" type="Enum">true</inlinedActionsBar> </parameters> </customControl> <customControl formFactor="2" name="MsdynmktControls.RichTextControl.RichTextControl"> <parameters> <value>cr65f_text</value> <emojiPickerEnabled static="true" type="Enum">false</emojiPickerEnabled> <isSingleLine static="true" type="Enum">false</isSingleLine> <personalizationEnabled static="true" type="Enum">true</personalizationEnabled> <personalizationPlaceholders>cr65f_placeholders</personalizationPlaceholders> <inlinedActionsBar static="true" type="Enum">true</inlinedActionsBar> </parameters> </customControl> </controlDescription> </controlDescriptions>
注:ID:05bb6ed1-e802-412c-9813-7eded53f3f73 对应new_text的uniqueid
导入发布后的效果:
7.Plugin代码抒写:
var tracingService = serviceProvider.Get<ITracingService>(); tracingService.Trace($"wechat:xx11113333xx"); throw new InvalidPluginExecutionException("heahahahahaahah111"); var pluginExecutionContext = serviceProvider.Get<IPluginExecutionContext>(); var organizationService = serviceProvider.Get<IOrganizationServiceFactory>().CreateOrganizationService(null); // 获取传过来的参数 var payload = pluginExecutionContext.InputParameters["payload"] as string; pluginExecutionContext.OutputParameters["response"] = payload + "[ooouuuttt]"; return;
注:入参和出差都是固定格式的,上面只是最简单的实例,在测试发送会报错:
需要调整为准确格式,可参考:链接待提供