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,205

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

  • Suggested answer
    Prutal Profile Picture
    10 on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

    i had the same issue.

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

  • ashlega Profile Picture
    34,477 on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

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

  • Shahbaaz Ansari Profile Picture
    6,205 on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

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

  • Verified answer
    ashlega Profile Picture
    34,477 on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

    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 )

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

    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.

  • Shahbaaz Ansari Profile Picture
    6,205 on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

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

  • Shahbaaz Ansari Profile Picture
    6,205 on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

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

  • Suggested answer
    Seenivasan Profile Picture
    on at
    RE: Passing Multiple Guid In QueryExpression using ConditionOperator.In

    Hi Shahbaaz ,

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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,245 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans