Add Conditions filter to QueryExpression give error: FilterExpression.Conditions has no setter

Leonard4p used Ask the Experts™

I'm trying to receive records from a dynamics crm 4.0 tabel. Receiving the records works fine. Hoever, when I add a filter (I only need some of the records), I got an error-meassage on

filter.Conditions = new ConditionExpression[] { condition };

The tooltip-text says: "The property has 'Microsoft.Crm.Sdk.Query.FilterExpression.Conditions' no setter".
Compiling results in 2 error messages: "Property or indexer 'Microsoft.Crm.Sdk.Query.FilterExpression.Conditions' cannot be assigned to -- it is read only"  and "Cannot implicitly convert type 'Microsoft.Crm.Sdk.Query.ConditionExpression[]' to 'System.Collections.ArrayList' "

Any clues?
private static BusinessEntityCollection GetCampaigns(bool toekomst)

            var query = new QueryExpression();
            query.ColumnSet = new AllColumns();
            query.EntityName = EntityName.campaign.ToString();

            // Retrieve the accounts where the last name is not Cannon.
            ConditionExpression condition = new ConditionExpression();
            condition.AttributeName = "crmrow_acc_startdatetime";
            if (toekomst)
                condition.Operator = ConditionOperator.OnOrAfter;
                condition.Operator = ConditionOperator.OnOrBefore;
            condition.Values = new object[] { DateTime.Now.ToShortDateString() };

            // Build the filter based on the condition.
            FilterExpression filter = new FilterExpression();
            filter.FilterOperator = LogicalOperator.And;
            filter.Conditions = new ConditionExpression[] { condition };
            // Set the Criteria field.
            query.Criteria = filter;

            // set request and execute it
            var request = new RetrieveMultipleRequest();
            request.Query = query;
            request.ReturnDynamicEntities = true;

            var response = (RetrieveMultipleResponse)CrmUtil.Service.Execute(request);
            return response.BusinessEntityCollection;

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008
While I am certainly not the CRM expert, I believe that what you are looking for is the FilterExpression.AddCondition method:

FilterExpression.AddCondition Method (Overloaded)


Thanks TheLearnedOne

The Condition filter and the FilterExpression.AddCondition Method didn't work for me, but I found a workaround, actually a very nice one.


        private static BusinessEntityCollection GetCampaigns(bool toekomst)
            //determine condition for xml query
            string condition = toekomst ? "next-x-years" : "last-x-years";

            //xml query: retrieve campaigns
            string fetchXml =
                    @"<fetch mapping='logical'>
                    	<entity name='campaign'>
                    		<attribute name='name' />
                    		<attribute name='typecode' />
                            <order attribute='crmrow_acc_startdatetime' />
                    			<condition attribute='crmrow_acc_startdatetime' operator='{0}' value='10' />
                    </fetch>", condition);
            var response = Processor.RetrieveMultipleWithFetchXml(fetchXml);
            return response;

Open in new window


this wasn't actually the solution (my response with the fetchXML was), but thanks anyway theLearnedOne

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial