Hi All,
i want to retrieve multiple accounts by passing multiple account guid in query expression. Below is my code
Guid[] accoundIds = new Guid[2];
accoundIds[0] = new Guid("67B9EAD9-B305-E811-8103-XXXXXXXXX");
accoundIds[1] = new Guid("2D39D37E-E70B-E811-8121-XXXXXXXXX");
var getfavAccount = new QueryExpression();
getfavAccount.EntityName = "account";
getfavAccount.ColumnSet = new ColumnSet("new_fav");
getfavAccount.Criteria.AddCondition("accountid", ConditionOperator.In, accoundIds);
EntityCollection retrieveAccounts = _serviceProxy.RetrieveMultiple(getfavAccount);
But i am getting below exception
{"The formatter threw an exception while trying to deserialize the message: There was an error while trying
to deserialize parameter schemas.microsoft.com/.../Services:query. The InnerException
message was 'Error in line 1 position 8431. Element 'schemas.microsoft.com/.../Arrays:anyType'
contains data from a type that maps to the name 'System:Guid[]'. The deserializer has no knowledge of any type that maps to this name.
Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'Guid[]'
and namespace 'System'.'.
Please see InnerException for more details."}
*This post is locked for comments
i had the same issue.
solution was to pass ids as array of strings instead on array of guids
It seems to be because of this:
" The constructor for ConditionExpression takes 5 overloads, and the compiler will use System.Collections.ICollection for the array of Guids. However, the AddCondition method only offers one type for the third parameter (params object[]). The result of this is that the code fails because the parameter is interpreted as object[] {new Guid[] { g1, g2 }}."
Thanks Alex it worked, but can you tell me why my above code is not working?
Hi,
using your original code, try this instead:
getfavAccount.Criteria.AddCondition(
new ConditionExpression("accountid", ConditionOperator.In, accoundIds));
(for more details, have a look at this post:
Hi Shahbaaz,
Please refer the below blog which has the explanation of this and a solution. This looks like a known issue-
mscrmuk.blogspot.com.au/.../unexpected-error-with.html
community.dynamics.com/.../crm-2011-odd-error-with-query-expression-and-conditionoperator-in
Hope this helps.
It is strange that when i am using In operator with link entity it is working fine...below is my code
Guid[] arrayOfAccountId = new Guid[2];
arrayOfAccountId[0] = new Guid("67B9EAD9-B305-E811-8103-xxxxxxx");
arrayOfAccountId[1] = new Guid("2D39D37E-E70B-E811-8121-xxxxxxx");
var getOpportunityCount1 = new QueryExpression();
getOpportunityCount1.EntityName = "account";
getOpportunityCount1.LinkEntities.Add(new LinkEntity("account", "opportunity", "accountid", "parentaccountid", JoinOperator.Inner));
getOpportunityCount1.LinkEntities[0].EntityAlias = "opportunity";
getOpportunityCount1.LinkEntities[0].Columns.AddColumns("opportunityid");
getOpportunityCount1.LinkEntities[0].LinkCriteria.Filters.Add(
new FilterExpression()
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("parentaccountid", ConditionOperator.In,arrayOfAccountId)
}
}
);
getOpportunityCount1.Distinct = true;
OrderExpression order1 = new OrderExpression("accountid", OrderType.Ascending);
getOpportunityCount1.Orders.Add(order1);
EntityCollection retrieveOpportunityCount1 = _serviceProxy.RetrieveMultiple(getOpportunityCount1);
Thanks SR for the reply, i also tried adding filter expression but no luck, below is my code
Guid[] accoundIds = new Guid[2];
accoundIds[0] = new Guid("67B9EAD9-B305-E811-8103-XXXXXXXXX");
accoundIds[1] = new Guid("2D39D37E-E70B-E811-8121-XXXXXXXXX");
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "accountid";
condition.Operator = ConditionOperator.In;
condition.Values.Add(accoundIds);
FilterExpression filter = new FilterExpression();
filter.AddCondition(condition);
var getfavAccount = new QueryExpression();
getfavAccount.EntityName = "account";
getfavAccount.ColumnSet = new ColumnSet("new_fav");
getfavAccount.Criteria.AddFilter(filter);
//getfavAccount.Criteria.AddCondition("accountid", ConditionOperator.In, accoundIds);
EntityCollection retrieveAccounts = _serviceProxy.RetrieveMultiple(getfavAccount);
Hi Shahbaaz ,
Instead of Specifying Account ID, Try to filter the Query Expression based on Account Guid by Adding Filter Expression.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156