1

I know how to make multiple/different calls to get details about all the fields and views in a list but I was wondering if there is a way to do it with one call.

I know I can use get_fields() and get_views() to get the fields/views but then I have to iterate them and make a 2nd call to load all the details.

I figured I can use get_schemaXml() to get the list schema but that doesn't include all the views and their schema.

function doIt()
{
    var clientContext;
    var oWebsite;
    var oList;
    var schema;

    clientContext = new SP.ClientContext.get_current();
    oWebsite = clientContext.get_web();
    oList = oWebsite.get_lists().getByTitle("Announcements");

    clientContext.load(this.oList, "SchemaXml");

    clientContext.executeQueryAsync(
        Function.createDelegate(this, successHandler),
        Function.createDelegate(this, errorHandler)
    );

    function successHandler(sender, args) {
        console.log(this.oList.get_schemaXml());
    }

    function errorHandler(sender, args) {
        console.log(args);
    }
}

doIt()
1

Here is the method that I use. It uses AJAX and ODATA. It will give you the properties of both the fields and the views. You would just iterate over them afterwards. I can include more details latter.

var myFilter = 'lists/GetByTitle(\'Site Assets\')?$select=Fields,Views&$expand=Fields,Views',
    jax = $.ajax(get_SPFolderBaseData('webAbsoluteUrl', myFilter));

$.when(jax).then(dataInspec).fail(oops);

function dataInspec(d){
            var data = d.d;

            console.log('Data Inspec... ', d, ' just data... ', data);
        }

function get_SPData(root, url){
            return {
                url: _spPageContextInfo[root]+ '/_api/' + url,
                method: 'GET',
                headers: {
                    'accept': 'application/json;odata=verbose',
                    'x-RequestDigest': $('#_REQUESTDIGEST').val()
                }
            }
        }

function oops( sender, args) {
            var errObj = JSON.parse(sender.responseText),
                errMsg = errObj.error.message.value;

            console.log('Your Request Failed:\n Status: ' + sender.status+ '\n State: ' +sender.readyState+ '\n Status Text: ' +sender.statusText+ '\n Message: ' +errMsg);
        }

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.