简体   繁体   中英

Dynamics CRM SDK filter query on custom field

I am trying to pull items from the salesorder entity into my WPF Application (C#) I have created a custom field in the crm called new_xero and published. This is a two-option field. I have 4 orders, 2 with nothing set for this field, one with 'no' selected and one with 'yes' selected.

I have the following code:

QueryExpression qeLocations = new QueryExpression("salesorder");

        string[] cols = { "salesorderid", "name" };
        qeLocations.ColumnSet = new ColumnSet(cols);


        var locations = this.OrgService.RetrieveMultiple(qeLocations);

        listBox1.ItemsSource = (from location in locations.Entities
                                where location.GetAttributeValue<string>("new_xero") == "false"
                                //where (bool)location["new_xero"] == false
                                    select new
                                    {
                                        Name = location["name"],
                                        LocationID = location["salesorderid"]
                                    }).Take(5);

It seems that everything I try to do to the line where location.GetAttributeValue<string>("new_xero") == "false" I can't filter to only those where the option is set to 'no' I have tried int filtering against 0, string against 'false', 'False', 'No', 'no' but can't seem to find the right solution.

Cheers

Found the answer, I needed to add the field new_xero to the cols array. Then either where location.GetAttributeValue<bool>("new_xero") or where location["new_xero"].ToString() == "False" (although opposing for true and false!

Many thanks, Chris

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