在CRM 2011中检索插件上的“两个选项”字段值

时间:2013-03-28 21:21:40

标签: dynamics-crm-2011 crm

我尝试根据帐户表单中的“两个选项”字段更新子联系人。如果“双选项”字段设置为“是”,我将所有子联系人更新为父帐户的更新地址。 我尝试使用以下代码检索值

bool? updateContactsValue 
  = entity.GetAttributeValue<bool?>("abc_yesNoField");

if (updateContactsValue)
{
  String[] details = new string[7];
  String telephoneNum = String.Empty, ... , country = String.Empty;

  telephoneNum = entity.GetAttributeValue<String>("telephone1");
  details[0] = telephoneNum;
  ...

  UpdateContact(service, entity.Id, details);
}

但我发现即使所选选项为“是”,地址字段也不会更新。我在这里错过了什么吗?

大家好, 我已将代码修改为如下

bool? updateContactsValue=null; 
updateContactsValue = entity.GetAttributeValue<bool?> ("abc_yesNoField").GetValueOrDefault();

throw new Exception( "My custom Exception"+" "+entity.GetAttributeValue<bool?>("abc_yesNoField").GetValueOrDefault().ToString());  

即使我选择了“是”,系统也会抛出“假”。

4 个答案:

答案 0 :(得分:1)

你的字段名称可能写错了,它不能是“updatechildcontacts”。 因为它是自定义字段,所以它必须以前缀开头,例如new_updatechildcontacts

答案 1 :(得分:1)

它只是一个嘻哈的镜头,因为我现在不在电脑前,但我相当肯定你(出于某种原因,我无法告诉你)现在),无法获取值并使 bool 为空。并且更新的执行取决于它是 true

您需要以不同的方式检查字段的值。

我不确定,但我希望yes / no元素是 bool ,而不是可空的bool 。如果你这样做会怎么样?它编译吗?

bool updateContactsValue 
  = entity.GetAttributeValue<bool>("abc_yesNoField");

if (updateContactsValue) { ... }

答案 2 :(得分:1)

错误在查询语句中,请确保您已在其中插入属性。如果未插入,它将始终为您提供错误值,例如:

QueryExpression query = new QueryExpression("ntw_abc");
query.ColumnSet = new ColumnSet("ntw_referencenumber", "abc_yesNoField");

答案 3 :(得分:1)

可能是问题,因为您使用的是 Scheema Name ,即混合大小写。 abc_yesNoField 不能是属性名称bcoz它使用混合大小写。 它应该是LowerCase,如 abc_yesnofield

bool? updateContactsValue= entity.GetAttributeValue<bool?>("abc_yesnofield");

始终在以下位置使用属性的逻辑名称,即名称(始终为小写):
1. Xrm
2. c#代码后期绑定

使用属性的 Scheema Name ,例如(混合大小写或驼峰大小写): 1. REST / oData / JSON对象模型
2. c#早期绑定类(LINQ)