I'm trying to return a list and order it by a choice field.

My choice field currently is just set to Yes or No.

The XML I'm using:

<View><Query><OrderBy><FieldRef Name="TestSort"/></OrderBy></Query></View>

I've also tried the properties in all combinations like:

<View><Query><OrderBy Override = "TRUE"><FieldRef Ascending = "TRUE" UseIndexForOrderBy = "FALSE" Name="TestSort"/></OrderBy></Query></View>

If I change the xml to either a date field or text field it works perfectly?

<View><Query><OrderBy><FieldRef Name="Created"/></OrderBy></Query></View>
<View><Query><OrderBy><FieldRef Name="Title"/></OrderBy></Query></View>

I've also tried using GroupBy rather than OrderBy but just cant get it working!!! Anybody have any ideas?

  • 1
    Are you sure that the internal name of your column is TestSort? – Eric Alexander Mar 24 '16 at 15:45
  • Can you only sort on internal names? Ive added a custom column called TestSort? – MPJ Mar 24 '16 at 15:48
  • CAML queries use the internal name of the column, is it for certain TestSort? – Eric Alexander Mar 24 '16 at 16:40
  • To check the internal name of the column, go into List Settings and edit the column. The internal name will be at the end of the URL – Erin L Mar 25 '16 at 13:43

The first line of XML you posted should work.

As Eric suggested confirm that the column name is correct.

Another thing to check is if the column allows multiple selections. You won't be able to sort if this is a multiple selection choice column.

| improve this answer | |
  • Thanks for taking the time to answer. That's the issue then, its a multiple selection. Is there no way of achieving this then? The issue I have is I have several list items, all of which can have one or many categories, I want to access these and display each category at different points. I tried doing a call for each category so I had several result sets but as the call uses callbacks it obviously gets quite messy as the calls are asynchronous. I know I could just drop several filtered web parts on the site but it doesn't really gove me the control or aesthetics that I wanted – MPJ Mar 29 '16 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.