Hi all,
I'm writing code to find the GUID of an Entity based on another unique field (old ID from previous CRM system). This is my first code to interact with Dynamics Online CRM, so I've been trying to follow an example that would give me code like...
_DynamicsConnection = CrmConnection.Parse(_ConfigSettings.DynamicsConnectionString);
... where the string passed to the Parse method would look like...
Once I have the connection, I'm trying to use a QueryExpression to get the GUID of an Account (for example). The code I'm running looks like...
string OldIDField = "name of field that holds old CRM ID";
string ConsolidationDataSourceField = "a field set up to tell us what source a record came from";
string ConsolidationDataSource = "the value of which source I care about at the moment";
string EntityString = "account";
string EntityIDField = "accountid";
ConditionExpression DataSourceMatch = new ConditionExpression();
DataSourceMatch.AttributeName = ConsolidationDataSourceField;
DataSourceMatch.Operator = ConditionOperator.Equal;
DataSourceMatch.Values.Add(ConsolidationDataSource);
ConditionExpression OldIDMatch = new ConditionExpression();
OldIDMatch.AttributeName = OldIDField;
OldIDMatch.Operator = ConditionOperator.Equal;
OldIDMatch.Values.Add("the old ID I'm looking for");
FilterExpression WhereClause = new FilterExpression();
WhereClause.Conditions.Add(DataSourceMatch);
WhereClause.Conditions.Add(OldIDMatch);
QueryExpression QueryObject = new QueryExpression(EntityString);
QueryObject.ColumnSet.AddColumn(EntityIDField);
QueryObject.Criteria.AddFilter(WhereClause);
EntityCollection QueryResult = DynamicsService.RetrieveMultiple(QueryObject); //The line that fails with an obscure exception
int ResultCount = QueryResult.TotalRecordCount;
FoundEntity = (ResultCount == 1);
if (FoundEntity)
{
DynamicsID = QueryResult[0].Id;
}
The call to "RetrieveMultiple" is where the code fails with a strange exception that I'm not sure how to look for: "System.InvalidOperationException: 'Metadata contains a reference that cannot be resolved:". Then it lists the URL of my Dynamics instance, except that the end of it has non-roman letters that look like middle eastern script. Here's the QueryString portion of the URL...
BackUri=&ErrorCode=&Parm0=%0d%0a%0d%0aتفاصيل الخطأ
The exception continues by saying "Object reference not set to an instance of an object."
I'm not sure what to do next, which is why I'm writing here. I appreciate any help that can be given.