web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Passing Multiple Guid In QueryExpression using ConditionOperator.In

(0) ShareShare
ReportReport
Posted on by 6,211

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 have the same question (0)
  • Suggested answer
    Seenivasan Profile Picture
    on at

    Hi Shahbaaz ,

    Instead of Specifying Account ID,  Try to filter the Query Expression based on Account Guid by Adding Filter Expression.

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    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);

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    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);

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    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:

    https://community.dynamics.com/crm/b/crmdavidjennaway/archive/2011/05/25/unexpected-error-with-conditionoperator-in-and-typed-arrays )

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    Thanks Alex it worked, but can you tell me why my above code is not working?

  • ashlega Profile Picture
    34,477 on at

    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 }}."

  • Suggested answer
    Prutal Profile Picture
    10 on at

    i had the same issue.

    solution was to pass ids as array of strings instead on array of guids

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans