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

狂风中的少年 提交于 2019-12-23 04:43:55

问题


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:


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);
            }
        }


来源:https://stackoverflow.com/questions/26237511/not-able-to-perform-filter-on-dynamics-crm-opportunity-transaction-type-with-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!