在选择列表中获取期权的价值 [英] Obtaining the value of an option in a picklist

查看:79
本文介绍了在选择列表中获取期权的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建实体 beep 的虚假实例。它具有一个类型为 picklist 的必填字段,称为 pickaboo 。首先,我忽略了它,但是随后由于某些业务逻辑要求所有新创建的 beep 实例分配该字段,应用程序开始向我抛出错误消息。

I'm creating a phony instance of an entity beep. It has a required field of type picklist called pickaboo. First I omitted it but then the application started to lament throwing error messages at me due to some business logic demanding all the newly created instances of beep to have that field assigned.

Entity entity = new Entity { LogicalName = "beep" };
Guid guid = proxy.Create(entity);
proxy.Delete("beep", guid);

我没有在啮齿类动物的尾巴部分提到这个需求,因为在创建实例之后,我将其删除。但是,CRM带来了巨大的麻烦,并且让我无法发挥自己的魔力。因此,我变得很聪明,为缺少的属性添加了一个属性。

I don't give a rodent's tail section about that demand because right after I've created the instance, I'm removing it. However CRM gives a huge rodent and doesn't let me do my magic. So, I went clever and added an attribute for the missing attribute.

OptionSetValue option = new OptionSetValue(0);
Entity entity = new Entity { LogicalName = "beep" };
entity.Attributes.Add("pickaboo", option);
Guid guid = proxy.Create(entity);
proxy.Delete("beep", guid);

当然,它没有用,因为零不是有效值。显然,CRM基于该解决方案添加了一个哈希数,因此实际的零具有类似 846000000000的数值,实际的 1具有 846000000001等。

Of course, it didn't work because zero isn't a valid value. Apparently, CRM adds a hash number based on the solution so the actual "zero" has the numeric value like "846000000000", the actual "one" has "846000000001" etc.

如何以编程方式获取该值?

How can I obtain that value programmatically?

现在我有一个丑陋的解决方法,可以获取所有蜂鸣声 s ,并从第一个中获取价值。我什至不让我开始失去多少睡眠,知道它看起来多么令人尴尬,有人会花时间给我一些反馈。 :(

推荐答案

您有两个选择。


  1. 您可以使用CrmSrvcUtil生成枚举的OptionSetValues ...这将创建一个pickaboo枚举,然后您可以在代码中引用
    entity.Attributes.Add( pickaboo,新的OptionSetValue((int)pickaboo.YourEnumValue);

您也可以使用 RetrieveOptionSetRequest 消息获取您感兴趣的特定选项集的所有值的列表。请参见这个SO问题

You could also use the RetrieveOptionSetRequest message to get a list of all values for the particular option set you're interested in. See this SO question

这篇关于在选择列表中获取期权的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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