QueryByAttribute(Dynamics CRM 2013)null引用异常
本文关键字:null 引用 异常 2013 Dynamics CRM QueryByAttribute | 更新日期: 2023-09-27 18:27:39
我有以下代码,它正在执行重复检测请求(通过CRM查看时成功),但当我试图查询检测作业的结果时,在运行代码的最后一行时,我得到了一个空引用(对象未设置为对象的实例)。
_response.jobid不为null,此时与CRM的连接仍然有效,因为我运行了一个单独的实体。在此阶段检索(不包括在代码中)以确保。有人能告诉我我缺了什么吗?此代码主要取自示例代码,但适用于我们的自定义实体。
// Create the BulkDetectDuplicatesRequest object
Console.WriteLine("Creating the BulkDetectDuplicatesRequest object");
BulkDetectDuplicatesResponse _response;
BulkDetectDuplicatesRequest request = new BulkDetectDuplicatesRequest()
{
JobName = "Detect Duplicate Supplier Invoices",
Query = new QueryExpression()
{
EntityName = "custentityname",
ColumnSet = new ColumnSet(true)
},
RecurrencePattern = String.Empty,
RecurrenceStartTime = DateTime.Now,
ToRecipients = new Guid[0],
CCRecipients = new Guid[0]
};
// Execute the request
Console.WriteLine("Executing BulkDetectDuplicatesRequest");
_response = (BulkDetectDuplicatesResponse)_serviceProxy.Execute(request);
try
{
BulkImportHelper.WaitForAsyncJobCompletion(_serviceProxy, _response.JobId);
QueryByAttribute query8 = new QueryByAttribute()
{
ColumnSet = new ColumnSet(true),
};
query8.Attributes.Add("asyncoperationid"); //from sample code
query8.Values.Add(_response.JobId); //has the job id of the duplicate detection job
EntityCollection results8 = _serviceProxy.RetrieveMultiple(query8); //errors due to null reference exception
}
感谢
QueryByAttribute
需要指定实体名称
账户实体的示例:
QueryByAttribute querybyattribute = new QueryByAttribute("account"); // account entity
querybyattribute.ColumnSet = new ColumnSet("name", "address1_city", "emailaddress1");
querybyattribute.Attributes.AddRange("address1_city");
querybyattribute.Values.AddRange("Redmond");
EntityCollection retrieved = _service.RetrieveMultiple(querybyattribute);