I have the following code which is executing a duplicate detection request (successfully when viewed through CRM) but when I attempt to query the result of the detection job, I am getting a null reference (object not set to instance of an object) when running the last line of the code.
The _response.jobid is not null and the connection to CRM is still valid at this point, as I ran a separate Entity.Retrieve (not included in the code) at this stage to make sure. Can someone please tell me what me are missing? This code was largely taken from the sample code but adapted for our custom entity.
// 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
}
Thanks