Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Passing Multiple Guid In QueryExpression using ConditionOperator.In

Posted on by 6,203

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

Categories:
  • Suggested answer
    Prutal Profile Picture
    Prutal 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
    ashlega 34,473 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
    Shahbaaz Ansari 6,203 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
    ashlega 34,473 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
    RaviKashyap 55,406 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
    Shahbaaz Ansari 6,203 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
    Shahbaaz Ansari 6,203 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
    Seenivasan 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,513 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,862 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans