Not able to perform Filter on Dynamics CRM “Opport

2019-06-10 22:57发布

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.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-06-10 23:42

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);
            }
        }
查看更多
登录 后发表回答