locked
how to pass guidlist of contacts in conditionexpression RRS feed

  • Question

  • I need to pass a list of Guid of contacts in condition expression in dynamcis crm. How i can do that.
    Saturday, September 25, 2010 7:37 AM

Answers

  • Hi Amarsen,

     

            I have diagnosed that for 2000 records it works fine with ConditionOperator.In but fails afterwards. strange may be a bug or some limitation.

    • Marked as answer by RohitArora Wednesday, September 29, 2010 11:46 AM
    Tuesday, September 28, 2010 11:50 AM

All replies

  • You can create a condition expression using a conditionoperator  IN

    ConditionExpression ce = new ConditionExpression();
    ce.AttributeName = "contactid";
    ce.Operator = ConditionOperator.In;
    ce.Values = new object[]{"guid1","guid2"}; //Can also use an array

    Hope this helps. Amar
    Saturday, September 25, 2010 8:00 AM
  • I have 3330 guid's and made a object list of it. but it is not working
    Saturday, September 25, 2010 8:04 AM
  • Make an array of GUIDs as follows

    http://crmentropy.blogspot.com/2010/08/limiting-records-in-bulkdeleterequest.html

    User an array to pass to a conditional  expression


    Guid[] contacts = new Guid[3330]

    //TODO Populate the array contacts with Guid

    ConditionExpression ce = new ConditionExpression(); ce.AttributeName = "contactid"; ce.Operator = ConditionOperator.In; ce.Values = new object[]{contacts};

    Hope this helps. Amar
    • Proposed as answer by Amarsen Vangoor Saturday, September 25, 2010 5:48 PM
    Saturday, September 25, 2010 8:16 AM
  • It makes ce.Values a 2D array. I tried it another way. However i will try it this way also let me check
    Saturday, September 25, 2010 8:24 AM
  • i 'm getting following error now

     

    "\n  0x80040216\n  An unexpected error occurred.\n  Platform\n"

    Saturday, September 25, 2010 8:27 AM
  • from the link i am not able to pass the parameters in the constructor of conditionexpression.
    Saturday, September 25, 2010 8:31 AM
  • from the link i am not able to pass the parameters in the constructor of conditionexpression.
    Saturday, September 25, 2010 8:32 AM
  • you need to include Microsoft.Crm.Sdk , Microsoft.Crm.Sdk.Query namespace for this to work

    Hope this helps. Amar
    Saturday, September 25, 2010 1:36 PM
  • Hi Amarsen,

     

            I have diagnosed that for 2000 records it works fine with ConditionOperator.In but fails afterwards. strange may be a bug or some limitation.

    • Marked as answer by RohitArora Wednesday, September 29, 2010 11:46 AM
    Tuesday, September 28, 2010 11:50 AM
  • I think this is probably a SQL limitation. I recall that SQL server has a limit of around 2100 parameters in one query, and CRM will pass each guid as a parameter. You can check this by enabling CRM tracing, which should give the more detailed SQL error.

    Unfortunately I can't think of an obvious workaround. It may be that more recent versions of SQL do not have this SQL limit. Or, you could try splitting the query into several chunks (2000 ids at a time), and then recombine the results in your code


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Tuesday, September 28, 2010 1:24 PM
    Moderator