15

I'm trying to get information from a list in a custom SPField called "My Field" with the internal name "MyField" using this JavaScript code:

$.ajax({
    url: "http://<URL>/_api/web/lists/GetByTitle('Documents')/items?$select=MyField",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function(data){
        $.each(data.d.results, function (key, value) {
            console.log(value.MyField);
        });
    },
    error: function(error){
        console.warn(JSON.stringify(error));
    }
});

MyField has a custom field value type.

I found this description

Not all types of column are available via REST, most annoyingly managed metadata columns are amongst this group of unsupported column types. Further, not all types of column will return data for an entry just by including them in the $select parameter, an example of which is Lookup (single or multi-value) columns. ...

Is this still the case, and what do I have to implement in the custom SPField, to make it retrievable via REST ...

Any ideas what I'm doing wrong?

  • Try removing the select (i.e. bring back all the field values) and see if the value of MyField is included in the response. – Rob Windsor Apr 27 '15 at 15:51
  • @RobWindsor: Thanks, I've just tested it, but unfortunately it is returning undefined for all items and there is also no MyField member if I expand the value-objects ... also adding ?$select=* is not solving the issue... – Markus Apr 27 '15 at 16:54
  • 4
    do you mean you defined a custom field type like outlined here: msdn.microsoft.com/en-us/library/office/… if that's the case I would be surprised if the REST API would be able to return data from your field because it could possibly use some data structure that the REST API isn't designed to handle -- why did you decide to go with a custom field type if that's the case (for my own curiosity)? – John-M Apr 27 '15 at 18:57
  • 1
    You'll probably have to extend and deploy your own REST endpoint with your own functionality to accomplish this – Anders Aune Apr 28 '15 at 6:37
  • 1
    It may be possible to create a Calculated Column, then set its formula to be "[MyField]". The Calculated Column should be available via REST. – Omar Stewey May 19 '15 at 20:55
1

If my field is Taxonomy Column, I would take a look at this blog.

It explains how to retrive Taxonomy columns with REST.

Basically you need to do a Post to a different endpoint:

$.ajax({
    url: "http://sharepointificate/_api/web/Lists/GetByTitle('Documents')/GetItems(query=@v1)?@v1={'ViewXml':'<View><Query></Query></View>'}",
    type: "POST",
0

The below code gives the results of the field into a variable called myfield.

<script type="text/javascript">
SP.SOD.executeFunc('sp.js','SP.ClientContext',update);
var returnedItems;
function update(){

var context=new SP.ClientContext();
var list=context.get_web().get_lists().getByTitle('Documents');

var caml = new SP.CamlQuery();
caml.set_viewXml("<View><Query></Query></View>");
returnedItems=list.getItems(caml);
context.load(returnedItems);
context.executeQueryAsync(onSucceededCallback,onFailedCallback);

}

function onSucceededCallback(sender,args){
alert();
var enumerator = returnedItems.getEnumerator(); 

while(enumerator.moveNext()){
var listItem=enumerator.get_current();
var myfield=listItem.get_item('MyField');

}
    }

function onFailedCallback(sender,args){
alert("Failed to connect:  "+args.get_message());
}
</script>

You can access the variable in javascript and use it anywhere from JS

0

Can you try

dataType: "json",

after

type: "GET",
  • Hi Charles, I've finally tested it and is behaving exactly the same (as expected somehow ...) – Markus Nov 12 '15 at 15:39

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.