1

I am trying to get list data with an id from my SharePoint online through REST. I have my ajax call like below.

getFunction:function(id){ return new Promise(function (resolve, reject) { $.ajax({ async: true, method: 'POST', url:myUrl+"/_api/web/lists/GetByTitle('ABExtensionStore')/RenderListDataAsStream", headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: resolve }); }); }

As i was using the RenderListDataAsStream it is giving entire list data. But I need only few columns with an id. So can anyone suggest how to query those list items. Any help will be appreciated.

  • Refer this link. This will guide you to use caml query with REST API. stackoverflow.com/questions/40959179/… – Rohit Waghela Sep 22 '18 at 10:24
  • Glad for your reply. But it doest give values and will throw error. As I mentioned above in my question I used "RenderListDataAsStream". It doesnt work well with it. you can go through answer below I posted which got me answer. – raja gangadhar Sep 22 '18 at 10:52
0

Ok I got the result but there is no documentation or articles found on these properties used

this is what i found. But I did not found what is RenderOptions and what value should be given. If anyone know can share the answer.

   getFunction:function(id) {


      <---here we can write our CAML Query
    var caml = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value  Type='Counter'>"+id+"</Value></Eq></Where></Query><ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /></ViewFields></View>";

    return new Promise(function (resolve, reject) {
        $.ajax({
            async: true,
            method: 'POST',
            url:myUrl+"/_api/web/lists/GetByTitle('ABExtensionStore')/RenderListDataAsStream",
            data: JSON.stringify({
                parameters:{
                    RenderOptions:2, <-- based on this render options data will be produced
                    ViewXml:caml  <---here i gave a caml Query
                }
            }),

            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: resolve
        });
    });
}
0

You can pass the id of the item dynamically to the rest url and get only those items.

getFunction:function(id){
return new Promise(function (resolve, reject) {
$.ajax({
 async: true,
 method: 'POST',
 url:myUrl+"/_api/web/lists/GetByTitle('ABExtensionStore')/items(" + id + ")",
 headers: {
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
        // Returning the results
        resolve(data);
    },
    error: function (data) {
        reject(data);
    }
   });
 });
}
  • glad for your reply.. but once go through my question again. I wanted to use that "RenderListDataAsStream" . It doesn't support giving Id dynamically.By the way I got the solution. You can go through here link – raja gangadhar Sep 24 '18 at 5:20

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.