如何在crm的QueryExpression中的列中用默认值(即0或" NA")替换空值或空值

时间:2016-07-22 10:05:23

标签: dynamics-crm-2011 crm dynamics-crm-2013 query-expressions adxstudio-portals

我想要make查询表达式,其中一列包含值,或者根据条件它将为空或null。     示例 - 联系实体

firstName |姓氏|地址1

name1 | lastname1 |
name2 | lastname2 |地址

name3 | lastname3 |地址2

现在我想将这些空白列替换为' NA' 在sql中我们可以像这样编写查询 -

select isnull(address1,'NA') as address from contact

我想在查询表达式中编写相同的查询

1 个答案:

答案 0 :(得分:0)

无法获取fetchxml来替换服务器端的值。但是为什么不在获取属性值后更改属性值?你最终会得到相同的结果

const string defaultValue = "NA";
var result = service.RetrieveMultiple(queryExpression);

foreach (var entity in result.Entities)
 {
      if (!entity.Attributes.ContainsKey("address1"))
      {
         entity.Attributes.Add(new KeyValuePair<string, object>("address1", null));
      }
      entity["address1"] = entity["address1"] ?? defaultValue;
  }