【问题标题】:Microsoft Dynamics CRM 2016微软动态 CRM 2016
【发布时间】:2016-04-20 06:48:55
【问题描述】:

我正在尝试编写一个 fetch xml 以从 Facility/Equipment 实体中检索 BusinessUnitID 和 Equipment ID,我已经在 c# 代码中编写了这个 fetch xml,但它在行中抛出了一个空引用异常/System.NullReferenceException(BOLD'编辑线) 我在设施/设备实体中没有任何空值。 这是我的代码:

  private static OrganizationService _orgService;
  string fetchBU = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='equipment'>
        <attribute name='name' />
        <attribute name='equipmentid' />
        <order attribute='name' descending='false' />
      <filter type='and'>
         <condition attribute='businessunitid' operator='eq-businessid' />
      </filter>
    </entity>
   </fetch>";

EntityCollection ec = _orgService.RetrieveMultiple(new FetchExpression(fetchBU));
if (ec.Entities.Count > 0)
{
   Guid BusinessUnitId = (Guid)ec[0].Attributes["businessunitid"];
}

有人可以建议我吗? 提前致谢!

【问题讨论】:

    标签: c# dynamics-crm customization microsoft-dynamics dynamics-crm-2016


    【解决方案1】:

    您还需要在属性中添加businessunitid,而不仅仅是在条件中:

    string fetchBU = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
        <entity name='equipment'>
            <attribute name='name' />
            <attribute name='equipmentid' />
            <attribute name='businessunitid' />
            <order attribute='name' descending='false' />
          <filter type='and'>
             <condition attribute='businessunitid' operator='eq-businessid' />
          </filter>
        </entity>
       </fetch>";
    

    【讨论】:

    • 嗨 guido 首先感谢您回答问题。我仍然遇到同样的错误。请查看上面添加的图片。
    • 那么 _orgService 未使用您的连接详细信息进行初始化
    • 谢谢!连接出现问题。
    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多