Dynamics 365 Marketing 建立自定義渠道:大家知道,微軟官方檔案,也有很具體的介紹,但是大家發現按照微軟的官方介紹,少不了跳坑,這裡給大家整理分享一些。
1.建立2個實體:渠道【new_flashinfosmschannel】、訊息模板(設定表單)
注意:如果想用標準訊息模板,可以不用建立訊息模板
標準訊息模板效果:
2.匯出解決方案,往XML增加一個關係【EntityRelationship】
https://learn.microsoft.com/zh-cn/dynamics365/marketing/real-time-marketing-define-custom-channel-instance
注意:匯出的解決方案,需要包含實體【msdyn_channelinstance】
範例:
<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
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.在自定義渠道,就能看到新增的渠道