Dynamics CRM-访问自定义产品选项值 [英] Dynamics CRM - Accessing Custom Product Option Value

查看:68
本文介绍了Dynamics CRM-访问自定义产品选项值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式访问Label&是在MS CRM Dynamics中作为自定义字段创建的值字段吗?

Is there a way to programmatically access the Label & Value fields that has been created as a custom Field in MS CRM Dynamics please?

我添加了一个名为 new_producttypesubcode的自定义字段,例如,它具有2个选项, Trophy = 1000000,Kit = 10000001。

I have added a custom field called "new_producttypesubcode" which, for example, has 2 options, Trophy = 1000000 and Kit = 10000001.

我正在编写一个导入实用程序,该实用程序在客户网站与其CRM之间镜像产品,我想获取所有可能产品的列表CRM中的选项,以查看它们是否在网站中匹配。

I am writing an import utility that mirrors products between the customers website and their CRM and I want to get a list of all possible product options in the CRM to see if they are matched in the website.

因此,从本质上讲,我想...

So, in essence I want to...


  1. 获取可能的new_producttype子代码及其对应值的列表。

  2. 遍历网站中的产品变型。

  3. 如果产品变体名称与new_producttypecodes列表中的任何名称匹配,则添加值1000000

因此,如果我找到一个产品添加到网站并在CRM中存在标记为 Trophy和 Trophy的产品,然后新的OptionSetValue(100000001)

So, if I find a product added to the website and its marked as a "Trophy" and "Trophy" exists in the CRM then new OptionSetValue(100000001)

我希望很有道理...

I hope that makes sense...

谢谢

推荐答案

此函数检索一个当前用户本地化的可能值字典。摘自: CRM 2011以编程方式查找选取列表,选项集,状态码,状态码和布尔值(两个选项)

This function retrieves a dictionary of possible values localised to the current user. Taken from: CRM 2011 Programatically Finding the Values of Picklists, Optionsets, Statecode, Statuscode and Boolean (Two Options).

static Dictionary<String, int> GetNumericValues(IOrganizationService service, String entity, String attribute)
{
    RetrieveAttributeRequest request = new RetrieveAttributeRequest
    {
        EntityLogicalName = entity,
        LogicalName = attribute,
        RetrieveAsIfPublished = true
    };

    RetrieveAttributeResponse response = (RetrieveAttributeResponse)service.Execute(request);

    switch (response.AttributeMetadata.AttributeType)
    {
        case AttributeTypeCode.Picklist:
        case AttributeTypeCode.State:
        case AttributeTypeCode.Status:
            return ((EnumAttributeMetadata)response.AttributeMetadata).OptionSet.Options
                .ToDictionary(key => key.Label.UserLocalizedLabel.Label, option => option.Value.Value);

        case AttributeTypeCode.Boolean:
            Dictionary<String, int> values = new Dictionary<String, int>();

            BooleanOptionSetMetadata metaData = ((BooleanAttributeMetadata)response.AttributeMetadata).OptionSet;

            values[metaData.TrueOption.Label.UserLocalizedLabel.Label] = metaData.TrueOption.Value.Value;
            values[metaData.FalseOption.Label.UserLocalizedLabel.Label] = metaData.FalseOption.Value.Value;

            return values;

        default:
            throw new ArgumentOutOfRangeException();
    }
}

所以您需要执行以下操作:

So you would then need to do something like:

Dictionary<String, int> values = GetNumericValues(proxy, "your_entity", "new_producttypesubcode");

if(values.ContainsKey("Trophy"))
{
    //Do something with the value
    OptionSetValue optionSetValue = values["Trophy"];
    int value = optionSetValue.Value;
}

这篇关于Dynamics CRM-访问自定义产品选项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆