แชร์ผ่าน


รายละเอียดเค้าร่างเพื่อสร้างเทมเพลตการแมปเมตาดาต้า

นำไปใช้กับ: Dynamics 365 Contact Center—แบบสแตนด์อโลนและ Dynamics 365 Customer Service เท่านั้น

บทความนี้อธิบายรายละเอียด Schema ที่จําเป็นในการแม็ปข้อมูลจากผู้ให้บริการข้อมูลภายนอกไปยังเอนทิตีบทความให้ความรู้ และวิธีที่คุณสามารถเตรียมไฟล์ JSON การแม็ป Schema ของคุณเองโดยใช้ฟิลด์และแอตทริบิวต์ต่างๆ

ฟิลด์

ตารางต่อไปนี้แสดงรายการฟิลด์และรายละเอียดฟิลด์ที่คุณต้องใช้ในสคีมา JSON ของคุณ

ชื่อเขตข้อมูล คำจำกัดความ จำเป็น ค่า
ชื่อ ชื่อของข้อกําหนดเขตข้อมูล ไม่ สตริงที่ระบุชื่อของเขตข้อมูล
ชื่อฟิลด์เป้าหมายที่ไม่ซ้ํากัน ตัวระบุเฉพาะหรือคีย์สํารองของเอนทิตีบทความให้ความรู้ โดยปกติ ฟิลด์นี้เป็นรหัสในฝั่งผู้ให้บริการเนื้อหา ใข่ สตริงที่ระบุชื่อของเขตข้อมูล คุณสามารถตั้งค่าเป็น "msydn_externalreferenceid"
ContentTargetFieldName ไม่ควรเปลี่ยนค่าฟิลด์ ใข่ ตั้งค่าเป็น "เนื้อหา"
ApiPathLeafName ไม่ควรเปลี่ยนค่าฟิลด์ ใข่ ตั้งค่าเป็น "บทความความรู้"
List<FieldDefinitions> เป็นรายการของคําจํากัดความของฟิลด์ ใข่ ชุดของคําจํากัดความสําหรับฟิลด์ ดูตารางต่อไปนี้สําหรับรายการฟิลด์ที่รองรับสําหรับการตั้งค่าข้อกําหนดฟิลด์

คําจํากัดความของฟิลด์

ตารางต่อไปนี้แสดงรายการแอตทริบิวต์ที่จําเป็นและไม่บังคับซึ่งคุณสามารถใช้ในสคีมาการแมปข้อมูลเมตาของคุณ

ชื่อเขตข้อมูล คำจำกัดความ จำเป็น ค่า
TargetFieldName เป็นชื่อเขตข้อมูลเชิงตรรกะของแอตทริบิวต์เป้าหมายในเอนทิตีบทความให้ความรู้ ใข่ สตริงใดๆ ที่ระบุชื่อของฟิลด์เป้าหมาย
ประเภทฟิลด์เป้าหมาย ระบุชนิดของฟิลด์เป้าหมาย ใข่ สตริงที่ระบุชนิดของเขตข้อมูล
DocFieldSource ระบุวิธีการระบุและแก้ไขค่าฟิลด์ต้นทางในขณะรันไทม์ ใข่ ตั้งค่าเป็นชนิดแหล่งข้อมูลอย่างใดอย่างหนึ่งต่อไปนี้:
  • Regex
  • เมตา
  • ค่าคงที่
  • URL
  • เอกสาร
หากต้องการทราบเกี่ยวกับชนิดข้อมูลเหล่านี้ โปรดดูส่วน ชนิดแหล่งข้อมูลฟิลด์ ต่อไปนี้
DocFieldPattern ระบุลักษณะของฟิลด์เป้าหมายที่จะดึงข้อมูล ไม่ ตั้งค่านี้ตามค่า DocFieldSource ดูตัวอย่างด้านล่างเกี่ยวกับวิธีการตั้งค่า DocFieldPatterns
ความยาวสูงสุด คือความยาวสูงสุดของสตริงที่สามารถจัดเก็บไว้ในฟิลด์เป้าหมาย ไม่ใช่ สามารถใช้ได้เมื่อแอตทริบิวต์ TargetFieldType เป็นชนิด String Int
ใช้ RegexCapture เก็บรูปแบบ regex ที่ใช้กับ URL ได้ ไม่ใช่ สามารถใช้ได้เมื่อแอตทริบิวต์ TargetFieldType เป็นชนิด String และแอตทริบิวต์ DocFieldSource เป็นชนิด Url URL หรือสตริง

ชนิดแหล่งข้อมูลฟิลด์

ข้อมูลในผู้ให้บริการการค้นหาภายนอกสามารถตั้งค่าเป็นชนิดแหล่งข้อมูลฟิลด์ต่อไปนี้ได้:

  • นิพจน์ทั่วไป: ใช้เพื่อระบุชนิดข้อมูลนิพจน์ทั่วไป
  • เมตา: ใช้เพื่อระบุว่าค่าฟิลด์เป้าหมายได้มาจาก <เมตา> แท็กในบทความต้นฉบับ
  • ค่าคงที่: ใช้เพื่อตั้งค่าคงที่สําหรับฟิลด์เป้าหมาย
  • Url: ใช้เพื่อระบุ URL ของเอกสารต้นฉบับภายนอก
  • เอกสาร: ใช้เพื่อระบุเนื้อหา HTML ของบทความ

ข้อควรพิจารณาในการสร้างเทมเพลตการแมปข้อมูลเมตาของคุณเอง

เมื่อคุณพัฒนาสคีมาการแม็ปของคุณเอง คุณต้องแน่ใจว่าได้กําหนดค่าฟิลด์บังคับสองสามฟิลด์และตั้งค่าเริ่มต้นสําหรับข้อกําหนดฟิลด์บางรายการ

เทมเพลตการแมปของคุณต้องมีสิ่งต่อไปนี้

  • เขตข้อมูล UniqueTargetFieldName, ContentTargetFieldName และ ApiPathLeafName ฟิลด์เหล่านี้ต้องตั้งค่าเป็นค่าที่ต้องการดังนี้:

    • ตั้งค่า UniqueTargetFieldName เป็นฟิลด์ msdyn_externalreferenceid แบบสําเร็จรูปหรือฟิลด์แบบกําหนดเอง หากคุณใช้ช่องที่กําหนดเอง ให้ตรวจสอบให้แน่ใจว่าคุณได้เพิ่มช่องเป็นคีย์สํารอง ข้อมูลเพิ่มเติม: กําหนดคีย์สํารองเพื่ออ้างอิงเรกคอร์ด Dynamics 365
    • รวมฟิลด์ ContentTargetFieldName และตั้งค่าเป็น "เนื้อหา"
    • รวมฟิลด์ ApiPathLeafName และตั้งค่าเป็น "บทความความรู้"
    • ตรวจสอบให้แน่ใจว่าคุณได้จัดเตรียมการแม็ปสําหรับทั้งฟิลด์ UniqueTargetField และ ContentTargetField ในรายการ FieldDefinitions

    สคีมาการแมปของคุณจะมีลักษณะดังนี้:

    
      {
        "Name": "{To be filled by you}",
        "UniqueTargetFieldName": "msdyn_externalreferenceid",
        "ContentTargetFieldName": "content",
        "ApiPathLeafName": "knowledgearticles"
        "FieldDefinitions": []
      }
    
    
  • คุณต้องรวมรายการ FieldDefinitions ด้านล่าง และเติมข้อมูลแอตทริบิวต์ เช่น FieldUse, DocFieldSource, TargetFieldName และ TargetFieldType ด้วยค่าเริ่มต้น อย่าลืมรวมฟิลด์และแอตทริบิวต์ต่อไปนี้พร้อมค่า "as-is" ในเทมเพลตของคุณ อย่างไรก็ตาม คุณสามารถตั้งค่า Docfieldsource และ Docfieldpattern สําหรับฟิลด์ชื่อเรื่องและค่าเนื้อหาเป็น Regex, Meta,Document, Constant หรือ Url

    
      {
        "FieldUse": "Create",
        "DocFieldSource": "ArticlePublicNumber",
        "TargetFieldName": "articlepublicnumber",
        "TargetFieldType": "String"
      },
      {
         "DocFieldSource": "Constant",
         "DocFieldPattern": "true",
         "TargetFieldName": "msdyn_isingestedarticle",
         "TargetFieldType": "Boolean"
      },
      {
         "DocFieldSource": "Url",
         "TargetFieldName": "msdyn_ingestedarticleurl",
         "TargetFieldType": "String"
      },
      {
         "DocFieldSource": "DataProvider",
         "TargetFieldName": "msdyn_integratedsearchproviderid@odata.bind",
         "TargetFieldType": "String"
      },
      {
         "DocFieldSource": "Regex",
         "DocFieldPattern": "<title>(.*?)</title>",
         "TargetFieldName": "title",
         "TargetFieldType": "String"
      },
      {
         "DocFieldSource": "Url",
         "TargetFieldName": "msdyn_externalreferenceid",
         "TargetFieldType": "String",
         "UseRegexCapture": "^https://.*?/(.*?)/.*/.*?([0-9A-F]{8}[-](?:[0-9A-F]{4}[-]){3}[0-9A-F]{12})$"
     }, 
      {
         "DocFieldSource": "Document",
         "TargetFieldName": "content",
         "TargetFieldType": "String"
      }
    
    
  • หลังจากที่คุณแสดงรายการฟิลด์บังคับและข้อมูลแอตทริบิวต์แล้ว คุณสามารถรวมการแมปข้อมูลเมตาเพิ่มเติมและตั้งค่าแบบกําหนดเองสําหรับฟิลด์เหล่านั้นได้ ตัวอย่างเช่น คุณสามารถรวมชนิดเมตาของ DocFieldSource และตั้งค่าที่กําหนดเองสําหรับแอตทริบิวต์ได้ดังนี้

    
       {
         "DocFieldSource": "Meta",
         "DocFieldPattern": "description",
         "TargetFieldName": "description",
         "TargetFieldType": "String",
         "MaxLength": 155
        }
    
    

ตัวอย่างเทมเพลตการแมปข้อมูลเมตา

คุณสามารถใช้ตัวอย่าง JSON การแมปข้อมูลเมตาต่อไปนี้เป็นเท็มเพลตเพื่อสร้างเท็มเพลตการแมปแบบกําหนดเองได้


   {
     "Name": "Integrated Search Data Provider Name",
     "UniqueTargetFieldName": "msdyn_externalreferenceid",
     "ContentTargetFieldName": "content",
     "ApiPathLeafName": "knowledgearticles",
     "FieldDefinitions": [
     {
       "FieldUse": "Create",
       "DocFieldSource": "ArticlePublicNumber",
       "TargetFieldName": "articlepublicnumber",
       "TargetFieldType": "String"
      },
      {
        "DocFieldSource": "Constant",
        "DocFieldPattern": "true",
        "TargetFieldName": "msdyn_isingestedarticle",
        "TargetFieldType": "Boolean"
      },
      {
        "DocFieldSource": "Url",
        "TargetFieldName": "msdyn_ingestedarticleurl",
        "TargetFieldType": "String"  
      },
      {
        "DocFieldSource": "DataProvider",
        "TargetFieldName": "msdyn_integratedsearchproviderid@odata.bind",
        "TargetFieldType": "String"
      },
      {
        "DocFieldSource": "Regex",
        "DocFieldPattern": "<title>(.*?)</title>",
        "TargetFieldName": "title",
        "TargetFieldType": "String"
       },
       {
          "DocFieldSource": "Meta",
          "DocFieldPattern": "description",
          "TargetFieldName": "description",
          "TargetFieldType": "String",
          "MaxLength": 155
       },
       {
          "DocFieldSource": "Document",
          "TargetFieldName": "content",
          "TargetFieldType": "String"
        },
        {
          "DocFieldSource": "Url",
          "TargetFieldName": "msdyn_externalreferenceid",
          "TargetFieldType": "String",
          "UseRegexCapture": "^https://.*?/(.*?)/.*/.*?([0-9A-F]{8}[-](?:[0-9A-F]{4}[-]){3}[0-9A-F]{12})$"
        }
    ]
 }

แปลง แมปข้อมูลแหล่งข้อมูลภายนอกไปยังฟิลด์ความรู้

เมื่อคุณกําลังแมปข้อมูลจากผู้ให้บริการข้อมูลภายนอกไปยังเอนทิตีบทความให้ความรู้ ถ้าค่าแหล่งข้อมูลเป็นชนิดข้อมูลอื่น คุณต้องแปลงค่าก่อนที่คุณจะสามารถแมปไปยังแอตทริบิวต์ความรู้เป้าหมายได้ คุณสามารถสร้างปลั๊กอินและลงทะเบียนบน Create และ Update ข้อความเพื่อให้แอตทริบิวต์บทความองค์ความรู้เป้าหมายมีค่าแบบอินไลน์กับบทความจากผู้ให้บริการภายนอก

เมื่อต้องการแปลงและแมปค่าแหล่งข้อมูล ให้ดําเนินการขั้นตอนต่อไปนี้:

  1. สร้างเขตข้อมูลแบบกําหนดเองใน KnowledgeArticle เอนทิตี เรียนรู้เพิ่มเติมที่ วิธีการสร้างและแก้ไขคอลัมน์
  2. แมปค่าแหล่งข้อมูลภายนอกที่จําเป็นกับเขตข้อมูลแบบกําหนดเองที่สร้างขึ้นใหม่ เรียนรู้เพิ่มเติมที่ กําหนดค่าการแมปเค้าร่างบทความให้ความรู้ (ตัวอย่าง) นี่คือการแมปชั่วคราวที่ปลั๊กอินของคุณเลือกค่าแหล่งข้อมูล
  3. สร้างปลั๊กอิน เรียนรู้เพิ่มเติมที่ สร้างโครงการปลั๊กอิน
  4. คุณสามารถเขียนโค้ดของคุณเองเพื่อแปลงค่าแหล่งข้อมูลภายนอกและแมปไปยังแอตทริบิวต์บทความให้ความรู้เป้าหมายที่ต้องการได้
    ในตัวอย่างนี้ เราจะแสดงวิธีที่คุณสามารถแมปค่าแหล่งข้อมูลของชนิดสตริงกับแอตทริบิวต์เขตข้อมูลของบทความของชนิด OptionSet ในปลั๊กอินที่คุณสร้างขึ้น ให้แทนที่คลาสทั้งหมดด้วยโค้ดตัวอย่างต่อไปนี้

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Services;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

namespace PowerApps.Samples
{
   /// <summary>
   /// The plug-in shows the sample code to map the external source value to the target attribute, when they're of different types
   /// </summary>
   /// <remarks>
   /// To showcase the capabilities of the plugin, we have added 2 new attributes to the KnowledgeArticle entity.
   /// The first attribute new_documentationcentersourcevalue is a String attribute that is mapped to the external source value. This is a temporary mapping that stores the source value.
   /// The plugin picks up the source value from new_documentationcentersourcevalue. The source value can take the following values: Develop, Content, and Test.
   ///The second attribute, new_documentationcenter, is the target attribute of type OptionSet to which the source value must actually be mapped to.
   /// Develop with value 100000000, Content with value 100000001, and Test with value 100000002
   /// The goal of this plugin to read the value from the new_documentationcentersourcevalue, retrieve the option set metadata of the target attribute new_documentationcenter, and map it to the value in new_documentationcentersourcevalue.
   /// </remarks>
   public sealed class KnowledgePlugin : IPlugin
   {
       /// <summary>
       /// Execute method that is required by the IPlugin interface.
       /// </summary>
       /// <param name="serviceProvider">The service provider from which you can obtain the
       /// tracing service, plug-in execution context, organization service, and more.</param>
       public void Execute(IServiceProvider serviceProvider)
       {
           //Extract the tracing service for use in debugging sandboxed plug-ins.
           ITracingService tracingService =
               (ITracingService)serviceProvider.GetService(typeof(ITracingService));

           // Obtain the execution context from the service provider.
           IPluginExecutionContext context = (IPluginExecutionContext)
               serviceProvider.GetService(typeof(IPluginExecutionContext));

           // The InputParameters collection contains all the data passed in the message request.
           if (context.InputParameters.Contains("Target") &&
               context.InputParameters["Target"] is Entity)
           {
               // Obtain the target entity from the input parameters.
               Entity entity = (Entity)context.InputParameters["Target"];

               // Verify that the target entity represents knowledgearticle.
               if (entity.LogicalName != "knowledgearticle")
               {
                   tracingService.Trace("KnowledgePlugin: Plugin is incorrectly called for the entity: " + entity.LogicalName);
                   return;
               }

               //Skip the plugin for RootArticles
               const string isRootArticleAttributeName = "isrootarticle";
               bool isRootArticle = entity.GetAttributeValue<bool>(isRootArticleAttributeName);
               if (isRootArticle)
               {
                   tracingService.Trace("KnowledgePlugin: Returning for Root Article");
                   return;
               }

               try
               {
                   const string sourceValueAttributeName = "new_documentationcentersourcevalue";
                   const string targetValueAttributeName = "new_documentationcenter";

                   //Get the source value
                   string sourceValue = entity.GetAttributeValue<string>(sourceValueAttributeName);
                   if (string.IsNullOrEmpty(sourceValue))
                   {
                       tracingService.Trace("KnowledgePlugin: " + sourceValueAttributeName + " is not set");
                       return;
                   }

                   // Obtain the organization service reference.
                   IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                   IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                   // Retrieve the option set metadata of the target field.
                   OptionSetMetadata retrievedOptionSetMetadata = RetrieveOptionSet(service, entity, targetValueAttributeName, tracingService);

                   // Check if the source data value is present in the retrieved target option set metadata.
                   OptionMetadata matchedOptionMetadata = retrievedOptionSetMetadata?.Options?.First(optionMetadata => optionMetadata.Label.UserLocalizedLabel.Label == sourceValue);
                   if (matchedOptionMetadata == null || matchedOptionMetadata.Value == null)
                   {
                       tracingService.Trace("KnowledgePlugin: Matching OptionMetadata is not found");
                       return;
                   }

                   // Map the option set value of the string new_documentationcentersourcevalue to the target option set new_documentationcenter.
                   int optionSetValue = (int)matchedOptionMetadata.Value;
                   entity[targetValueAttributeName] = new OptionSetValue(optionSetValue);
                   tracingService.Trace("KnowledgePlugin: Successfully set the value.");
               }
               catch (FaultException<OrganizationServiceFault> ex)
               {
                   throw new InvalidPluginExecutionException("An error occurred in the KnowledgePlugin plug-in." + ex + "\n InnerException: " + ex.InnerException);
               }

               catch (Exception ex)
               {
                   tracingService.Trace("Exception in KnowledgePlugin: {0}", ex);
                   throw ex;
               }
           }
       }

       /// <summary> 
       /// Fetch the optionset metadata from the entity metadata
       /// </summary>
       /// <param name="service">Organization Details</param>
       /// <param name="entity">Entity record</param>
       /// <param name="targetValueAttributeName">Optionset Attribute Name</param>
       /// <param name="tracingService">Tracing Service</param>
       private OptionSetMetadata RetrieveOptionSet(IOrganizationService service, Entity entity, string targetValueAttributeName, ITracingService tracingService)
       {
           RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
           {
               LogicalName = entity.LogicalName,
               EntityFilters = EntityFilters.Attributes,
               RetrieveAsIfPublished = true
           };
           RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveEntityRequest);
           EntityMetadata metadata = retrieveEntityResponse.EntityMetadata;
           PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => string.Equals(attribute.LogicalName, targetValueAttributeName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;
           return picklistMetadata.OptionSet;
       }
   }
}


  1. ลงทะเบียนปลั๊กอินในCreateและUpdateข้อความ SDK ของเอนทิตี KnowledgeArticle ในขั้นตอนก่อนดำเนินการ ข้อมูลเพิ่มเติม: ลงทะเบียนปลั๊กอิน

จัดการตัวให้บริการค้นหาภายใน
ดูและใช้ข้อมูลเชิงลึกสำหรับตัวให้บริการค้นหา