3

I am trying to retrieve data from a custom list in SharePoint 2013. I created the list with several fields:

  • Title (single line text)
  • Subject (single line text)
  • Release Date (date/time)
  • Main Contact (person or group)
  • Priority (number).

I retrieve the list data using jQuery AJAX with the _api/lists/getbytitle('ListName')/items and I get data back but the field names are not correct. For example, the field name for the Subject field comes back as 'ym4b' and the field name for Priority is 'rq0x'. I don't have this problem when I get the list data using _vti_bin/listdata.svc/ListName, I get the fields back with the proper names. Can anyone shed some light on why this happens and how to fix it? I am hoping I'm missing something simple here because I really want to use the new API vs the old _vti_bin/listdata.svc version.

1

Those are the type of randomized names SharePoint generates when you create columns using the "Add Column" button in the "Edit this list" view.

You see this differently in the new _api endpoint than in listData.svc because the _api endpoints use internal names and listData.svc endpoints use display names for the JSON data member names.

You can avoid these random internal names by using the "Create Column" link from the list settings screen instead of using the "Add Column" link on the list view screen. The name you put into the Column Name field will be the column's internal name. Note - spaces and special characters will get encoded here, so it's best to use pascal case or some other naming convention with no spaces or special characters.

For completeness (I know it may not apply in your situation) you can define site columns in the UI to achieve the same effect. You can also modify the XML list definitions directly if you're using visual studio to load the definitions in.

  • Thanks for your help. Do you know of any work arounds with Sharepoint? Our users will most likely use the easiest way (the grid) to create their lists, can that be turned off? Anyway, big help and thank you. – bbonnet Feb 1 '16 at 15:34
  • well hopefully folks aren't adding columns like this that they're then expecting you to code a solution against, I would imagine you could turn off the interface item using client side rendering (CSR) or some similar approach but I would ask that as another question -- best bet to prevent this is some old fashioned site admin education, explain why this makes it hard to develop solutions for them -- you could also come in behind them and create columns with proper internal names and transfer the data over, but having them not make them in the first place would be best! – John-M Feb 1 '16 at 15:40
1

This is most probably because you created the columns in your custom list using the grid view, correct?

When you do this, SharePoint assigns these kinds of internal names to your columns, ym4b and rq0x etc.

Your 'new' API call is returning with the internal names of the columns.

Your 'old' API call is returning with neither the display nor the internal names. I don't have much experience with listdata.svc but I'm quite sure the result is showing column names in a different manner.

For example, in my site I have a column whose internal name is EnvType and whose display name is Environment Type. But the result I get back from listdata.svc is EnvironmentTypeValue. Go figure :)

To avoid this issue with internal column names, DON'T create columns using the grid view.

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.