简体   繁体   中英

Not able to perform Filter on Dynamics CRM “Opportunity” transaction type with estimatedclosedate

I am using QueryExpression to generate the filter for the Dynamics crm filters and then passing that to the my CRM made service to retrieve the result.

QueryExpression queryCRM = new QueryExpression
                {
                    EntityName = SourceID,
                    ColumnSet = new ColumnSet(FieldSet),
                    Criteria = new FilterExpression()
                };

and then

queryCRM.Criteria.AddCondition(strFilterColumnName,ConditionOperator.On , strFilterValue);

Here i am not able to fetch the result can anybody help me to figure out the issue? It doesn't work for "estimatedclosedate" other than this it works fine withe all other columns.

Note := Initially it seems like an operator issue so i used "ConditionOperator.On" , so it solved my issue for Incident but not for opportunity.

Need solution from the CRM experts out there.

Thank You.

Is strFilterValue a string? Try and pass this parameter as a DateTime. It would help if you could post this section of code in it's entirety. Here's some sample code which demonstrates the use of filtering an opportunity by estimated close date.

        var estimatedCloseDate = DateTime.Parse("2014-10-07");
        Guid createdId = Guid.Empty;
        Entity matchingEntity = null;

        try
        {
            // Create a test opp
            var opp = new Entity("opportunity");
            opp["name"] = "Testing Date Filter";
            opp["customerid"] = new EntityReference("account", Guid.Parse("b9b0ed35-2a11-4fb6-a56f-5b8c04a3c1d1")); // A valid customer
            opp["estimatedclosedate"] = estimatedCloseDate;
            createdId = _service.Create(opp);
            Console.WriteLine("Created Id: {0}", createdId);

            // Create the filter expression
            QueryExpression queryCRM = new QueryExpression
            {
                EntityName = "opportunity",
                ColumnSet = new ColumnSet(true)
            };
            queryCRM.Criteria.AddCondition("estimatedclosedate", ConditionOperator.On, estimatedCloseDate);

            // Run the search and check for a match vs the record just created
            var results = _service.RetrieveMultiple(queryCRM);
            foreach (var result in results.Entities)
            {
                if (result.Id == createdId)
                {
                    matchingEntity = result;
                }
            }

            // Survey says... 
            Console.WriteLine(matchingEntity == null
                                ? "Matching entity not found!"
                                : "Matching entity found!");
        }
        finally
        {
            // Delete the created opp
            if (createdId != Guid.Empty)
            {
                _service.Delete("opportunity", createdId);
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM