Monday, September 18, 2017

RetrieveMultiple Using Newest Dynamics 365 SDK Gives Weird Behavior When Filtering on StateCode

Why in the world would it now be necessary to search using a conditionexpression on statecode by the strings "Active" or "Inactive"  instead of just taking the integer values of the optionset when performing a retrievemultiple request in a custom workflow activity.




 if (targetChildStateCode == 0)
                {
                    strTargetChildStateCode = "Active";
                }
                else if (targetChildStateCode == 1)
                {
                    strTargetChildStateCode = "Inactive";
                }
                int targetChildStatusReason = TargetChildStatusReason.Get(activityContext);
                tracingService.Trace("targetChildStateCode: " + targetChildStateCode.ToString());
                tracingService.Trace("targetChildStatusReason: " + targetChildStatusReason.ToString());
                tracingService.Trace("got parameters");
                tracingService.Trace("defined criteria and paging info");
               
                RetrieveMultipleRequest rmr = new RetrieveMultipleRequest();
                RetrieveMultipleResponse resp = new RetrieveMultipleResponse();
               
                QueryExpression query = new QueryExpression()
                {
                    EntityName = childEntityName,
                    ColumnSet = new ColumnSet(true),
                    Criteria = new FilterExpression
                    {
                        FilterOperator = LogicalOperator.And,
                        Conditions =
                        {
                            new ConditionExpression
                            {
                                AttributeName = childLookupAttributeToParent,
                                Operator = ConditionOperator.Equal,
                                Values = { primaryEntityId.ToString() }
                            },
                            new ConditionExpression
                            {
                                AttributeName = "statecode",
                                Operator = ConditionOperator.NotEqual,
                                Values = { strTargetChildStateCode }
                            }
                        }
                    }
                };
 


-head scratcher....

2 comments:

  1. Good Post. Avail Microsoft Dynamics Web Development Service that transform your business with customized business solutions.

    ReplyDelete
  2. Interesting solution. I recently introduced an ERP system in my company and I am very satisfied! I would never have thought that it could be so useful :)
    Now I am thinking about the next solution. I want to bet on cloud solutions.
    I've read a lot about it and I think it can be a great topic. What do you think about it? I even found a company that specializes in it - this .
    I am happy to hear more from you about it - if you had to deal with it :)

    ReplyDelete