【问题标题】:invalid Argument error while retrieving values from lookup field从查找字段中检索值时出现无效参数错误
【发布时间】:2018-01-10 06:20:46
【问题描述】:

我在潜在客户实体上有帐户和联系人查找字段。我想获取联系人的帐户名称和电子邮件地址。

我收到无效参数错误。

代码:

    public EntityCollection  GetDetails()
    {
        string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                      <entity name='lead'>
                        <attribute name='fullname' />
                        <attribute name='leadid' />      
                        <attribute name='new_contact'/>
                        <attribute name='new_account'/>
                        <order attribute='fullname' descending='false' />
                        <filter type='and'>                             
                          <condition attribute='leadqualitycode' operator='eq' value='1' />
                        </filter>                            
                      </entity>
                    </fetch>";
        EntityCollection records = service.RetrieveMultiple(new FetchExpression(fetchXML));
        return records;         
    }

    public string GetAccountDetail(EntityCollection records)
    {
        if (records.Entities.Count != 0)
        {
            accountid = records.Entities[0].GetAttributeValue<Guid>("new_account");
            tracingService.Trace("AccountId :" + accountid);
            Entity accountDetails = service.Retrieve("account", accountid, new ColumnSet("name"));
            string accountname = accountDetails.Attributes["name"].ToString();              
            tracingService.Trace("AccountName :" + accountname);
            return accountname;
        }
        return name;
    }

【问题讨论】:

  • Service.Retrieve
  • 我只使用它,但我收到了 Invalid Argument 错误。
  • 您确定这些字段名称正确吗?查找字段通常为xxx_lookupid 格式。
  • @JamesWood 字段名称正确。
  • 我在 accountid 行上收到此错误:发生“System.InvalidCastException”类型的异常

标签: c# plugins dynamics-crm microsoft-dynamics dynamics-crm-online


【解决方案1】:

改变这一行

accountid = records.Entities[0].GetAttributeValue<Guid>("new_account");

进入

accountid = records.Entities[0].GetAttributeValue<EntityReference>("new_account").Id;

因为它是一个查找。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 2023-03-13
    • 2021-12-22
    相关资源
    最近更新 更多