0

我有一個小工具,用於將實體從Microsoft Dynamics 365 Crm 2016實例傳輸到另一個實例。我成功轉移了沒有任何依賴的實體;但是當我嘗試傳輸某些選項集設置的實體時,垂直,部門,我因爲這些選項集而出現錯誤在目標實例中不存在。如何使用Microsoft Xrm Sdk傳輸選項集/擴展

我在下面的圖片上籤了這些選項集。 enter image description here

我的問題是我不知道如何以編程方式回顧這些擴展。我已經使用下面的代碼來檢索所有選項集,但用戶定義的語言,垂直和其他選項集在repsonse中不存在。

RetrieveAllOptionSetsRequest retrieveAllOptionSetsRequest = new RetrieveAllOptionSetsRequest(); 
     var retrieveAllOptionSetsResponse =(RetrieveAllOptionSetsResponse)sourceService.Execute(retrieveAllOptionSetsRequest); 

任何想法?我應該發送哪些請求到源CRM實例以獲取所有用戶定義的選項集?

回答

1

這些實體可能有私人選項集。您可以使用這些方法爲每個實體檢索這些選項集(將實體的邏輯名稱傳遞給實體參數):

using System; 
using Microsoft.Xrm.Sdk; 
using Microsoft.Xrm.Sdk.Messages; 
using Microsoft.Xrm.Sdk.Metadata; 
using Microsoft.Xrm.Tooling.Connector; 
using System.Collections.Generic; 
using System.Linq; 

    private List<AttributeMetadata> getPicklists(IOrganizationService svc, string entity) 
    { 
     return allAttributes(svc, entity).Where(a => a.AttributeType == AttributeTypeCode.Picklist).ToList(); 
    } 

    //Retrieve all attributes of an entity 
    private List<AttributeMetadata> allAttributes(IOrganizationService svc, string entity) 
    { 
     var req = new RetrieveEntityRequest(); 

     req.EntityFilters = EntityFilters.Attributes; 

     req.LogicalName = entity.ToLower(); 

     var response = (RetrieveEntityResponse)svc.Execute(req); 

     return response.EntityMetadata.Attributes.ToList(); 
    }