0

我有一个小工具,用于将实体从 microsoft dynamics 365 crm 2016 实例转移到另一个实例。我成功转移了没有任何依赖的实体;但是当我尝试传输某些选项集设置的实体时——比如语言、垂直、部门——我得到错误,因为这些选项集在目标实例中不存在。

我在下图中签署了这些选项集。 在此处输入图像描述

我的问题是我不知道如何以编程方式检索这些扩展。我已经使用下面的代码来检索所有选项集,但用户定义的语言、垂直和其他选项集在响应中不存在。

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

任何想法 ?我应该向源 crm 实例发送哪个请求以获取所有用户定义的选项集?

4

1 回答 1

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();
    }
于 2017-09-26T12:51:20.157 回答