有没有办法以编程方式访问已在MS CRM Dynamics中创建为自定义字段的标签和值字段?
我添加了一个名为"new_producttypesubcode"的自定义字段,例如,它有2个选项,Trophy = 1000000和Kit = 10000001.
我正在编写一个导入实用程序,它反映客户网站和他们的CRM之间的产品,我想获得CRM中所有可能的产品选项列表,看看它们是否在网站上匹配.
所以,本质上我想......
所以,如果我发现一个产品添加到网站并且其标记为"Trophy"和"Trophy"存在于CRM中,那么新的OptionSetValue(100000001)
我希望这是有道理的...
谢谢
此函数检索本地化为当前用户的可能值的字典.摘自:CRM 2011以编程方式查找选项列表,选项集,状态代码,状态代码和布尔值(两个选项)的值.
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();
}
}
Run Code Online (Sandbox Code Playgroud)
所以你需要做的事情如下:
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3269 次 |
| 最近记录: |