Multiple conditions RRS feed

  • Question

  • I am trying to create multiple conditions in a dynamic entity.

    Basically, I am able to retrieve records with a "standard filter". Say, it returns me 3 entities - thats cool.


    Now after adding another filter, it seems to return 4 entities but that should not be the case, it should still be 3 as the new filter added, the condition for it is true (that a column matches a value in the given existing records) but it seems to return 4 (there are more than 4 records in MS CRM/database).


    Any ideas where I am going wrong? I am trying to add filtering/queries.


    ConditionExpression vacancyCondition = new ConditionExpression();
       for(int counter = 0; counter < entitiesFound.Length; counter++)
        ConditionExpression condition = this.CreateCondition("new_id", this.GetAttributeFieldValue(entitiesFound[counter], "new_id"), ConditionOperator.Equal);
        FilterExpression entityFilter = new FilterExpression();
        entityFilter.Conditions = new ConditionExpression[]{condition};
        entityFilter.FilterOperator = LogicalOperator.Or;
        query.Criteria.Filters = this.AddNewFilter(query.Criteria.Filters, entityFilter);
       //DynamicEntity[] results = this.GetAllRecords(query);
    //returns me 3 entities - GOOD.

       #region Vacancy Owner Condition
       if (matchEntityOwnerToCurrentUser)
        ConditionExpression ownerExpression = new ConditionExpression();
        FilterExpression ownerFilter = new FilterExpression();
        ownerFilter.FilterOperator = LogicalOperator.And;        
        ownerFilter.Conditions = new ConditionExpression[]{ownerExpression};
        ownerExpression.AttributeName = "owninguser";
        ownerExpression.Operator = ConditionOperator.Equal;
        ownerExpression.Values = new object[]{this.GetCurrentUserID()};  //WhoAmI
        query.Criteria.Filters = this.AddNewFilter(query.Criteria.Filters, ownerFilter);
    DynamicEntity[] results = this.GetAllRecords(query);
    //now I get 4 entities back, but it should be 3. so seems to be using some "or" condition but really should be an AND.


    Thursday, July 5, 2007 10:31 AM


  • As far as I understand your code, you have a list of ids and want to retrieve these entities at once. You also do a check for the owner, so here's waht you should do:


    ConditionExpression ownerCondition = new ConditionExpression();

    ownerCondition.AttributeName = "ownerid";

    ownerCondition.Operator = ConditionOperator.EqualUserId;


    ArrayList entityIds = new ArrayList();

    //populate the list with the entity identifiers


    ConditionExpression entityIdCondition = new ConditionExpression();

    entityIdCondition.AttributeName = "new_id";

    entityIdCondition.Operator = ConditionOperator.In;

    entityIdCondition.Values = entityIds.ToArray();


    FilterExpression filter = new FilterExpression();

    filter.Conditions = new ConditionExpression[] { ownerCondition, entityIdCondition };

    filter.FilterOperator = LogicalOperator.And;



    Saturday, July 7, 2007 5:57 PM