I get interesting questions all this time. This one came from a client who was trying to use GetListItems with SPServices in SharePoint .
Hey Marc, I’m trying to do a GetListItems operation on tasks list and I’m having trouble with the “Task Status” column. This is SP2013.
1 | var thisTaskStatus = $.trim($( this ).attr( "Status" )); |
2 | var thisTaskStatus = $.trim($( this ).attr( "ows_Status" )); |
3 | var thisTaskStatus = $.trim($( this ).attr( "ows_Task_x0020_Status" )); |
None of the above work and I went into the edit column settings of the task list and clicked on the status column and it says the field name is “Status”. When I look at the XML returned using Firebug, a lot of other fields show up like Title, Due Date, Created By, etc. but I don’t see the status column showing up at all in the responseXML.
Many of the out of the box columns have rather obscure StaticNames. In a Tasks list, the column which has the “Status” DisplayName has a StaticName of “Status” as well, so that’s pretty simple. Here’s the field definition, which I grabbed by calling GetList on my own Tasks list:
3 | < CHOICE >Not Started</ CHOICE > |
4 | < CHOICE >In Progress</ CHOICE > |
5 | < CHOICE >Completed</ CHOICE > |
6 | < CHOICE >Deferred</ CHOICE > |
7 | < CHOICE >Waiting on someone else</ CHOICE > |
10 | < MAPPING Value = "1" >Not Started</ MAPPING > |
11 | < MAPPING Value = "2" >In Progress</ MAPPING > |
12 | < MAPPING Value = "3" >Completed</ MAPPING > |
13 | < MAPPING Value = "4" >Deferred</ MAPPING > |
14 | < MAPPING Value = "5" >Waiting on someone else</ MAPPING > |
16 | < Default >Not Started</ Default > |
Calling GetList to take a look at the list schema is a good way to keep yourself from going crazy.
Now that said, you don’t always get all of the columns for a list when you call GetListItems. By default, you get the columns which are shown in the default view.
In an out of the box Tasks list that I just created, when I make this call:
2 | operation: "GetListItems" , |
Status isn’t returned because it’s not in the default view.
2 | ows_Checkmark = "boolean;#0" |
5 | ows_PercentComplete = "0.500000000000000" |
6 | ows__ModerationStatus = "0" |
10 | ows_UniqueId = "1;#{CC125F6A-F329-46D7-8140-F9353F1AC7EC}" |
11 | ows_owshiddenversion = "1" |
13 | ows_Created_x0020_Date = "1;#2014-01-29 13:04:43" |
14 | ows_Created = "2014-01-29 13:04:43" |
15 | ows_FileLeafRef = "1;#1_.000" |
16 | ows_PermMask = "0x7fffffffffffffff" |
17 | ows_Modified = "2014-01-29 13:04:43" |
18 | ows_FileRef = "1;#sites/Demos2013/jquerylib/Lists/Tasks/1_.000" > |
Instead, you can add the CAMLViewFields option to request it:
2 | operation: "GetListItems" , |
4 | CAMLViewFields: "<ViewFields><FieldRef Name='Status'/></ViewFields>" |
Then I get:
4 | ows__ModerationStatus = "0" |
8 | ows_UniqueId = "1;#{CC125F6A-F329-46D7-8140-F9353F1AC7EC}" |
9 | ows_owshiddenversion = "2" |
11 | ows_Created = "2014-01-29 13:04:43" |
12 | ows_PermMask = "0x7fffffffffffffff" |
13 | ows_Modified = "2014-01-29 13:11:21" |
14 | ows_FileRef = "1;#sites/Demos2013/jquerylib/Lists/Tasks/1_.000" > |
Being explicit about the columns you want to retrieve is always a good practice. People can change the default view easily.
This is great stuff, thanks! I follow-up — which attr data stores the relationship between tasks — i.e. summary vs child tasks? When I bring up tasks in a view in SP2013 I see a distinct hierarchical and physical ordering. But, when I query via SPServices, they come in completely scrambled.