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....

1 comment: