3

I am query a list via rest results I retrieve fine in Office 365 (sharepoint 2013).

I have two fields of which one is a managed metadata fields. I am looping through the results retrieved but when how do I get the value for the managed metadata fields.

The "Private Question" fields is not a metadata field. The Status field is a managed metadata field which is causing an issue

The code below is the javascript looping through each item to find the value of "Status" which is showing null.

                results.forEach(function (result) {
                if (result.Status.Label === "66") {
                    // THIS KEEP RETURNING NOTHING
                }
                if (result.Private_x0020_Question == true) {
                    count++;
                }
            });

Here is the watch window from chrome as I loop through each item.

enter image description here

Here are the results executed as a rest query straight in the browser (so you can view in a more displayable format).

enter image description here

Need to know how to get the value of the Status field please.

2 Answers 2

1

The following example works for me:

function getListItems(webUrl,listName, success, failure) {
    var url = webUrl + "/_api/web/lists/GetByTitle('" + listName +  "')/items";
    $.ajax({
        url: url,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data.d.results);
        },
        error: function (data) {
            failure(data);
        }
    });
}


//Usage
getListItems(_spPageContextInfo.webAbsoluteUrl,'Documents',function(results){

    results.forEach(function (result) {

        if(result.Status && result.Status.Label === "5"){
             console.log(result.Status.Label); 
        }

     });

  },
  function(error){
    console.log(JSON.stringify(error));
  }
);
3
  • He is asking how to get the metadata field, the metadata field tags only show when select multiple is allowed, in this case this is cannot be done as it is a status field. There is no Taxonomy namespace functionality in the REST api.
    – Hugh Wood
    Commented May 14, 2014 at 10:59
  • Vadim I have tried the above and this works fine. So I have marked your answer as the solution required. Thanks for all your help guys.
    – Miyagi
    Commented May 14, 2014 at 11:22
  • Hugh, thank you for the constructive critique, but I assume OP was asking about obtaining taxonomy values Commented May 14, 2014 at 15:38
0

The Taxonomy namespace isn't currently supported by the REST api. However you can access it via CSOM/JSOM. An example can be found here: SharePoint 2013: Create and retrieve taxonomic metadata in apps for SharePoint.

You can also use a wrapper library called SPServices to get the Term for you.

2
  • Do you have a code example
    – Miyagi
    Commented May 14, 2014 at 10:51
  • 1
    The code sample is in the link, its a downloadable project from MSDN that demonstrates working with Taxonomy
    – Hugh Wood
    Commented May 14, 2014 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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