0
        var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Privacy Statements');

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="IsActive"/><Value Type="Integer">1</Value></Eq></Where><OrderBy><FieldRef Name="SortOrder"/></OrderBy></View></Query>');
this.collListItem = oList.getItems(camlQuery);


clientContext.load(collListItem);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 

function onQuerySucceeded(sender, args) {

var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {

                        var oListItem = listItemEnumerator.get_current();

                        listTitle.push(oListItem.get_item('Title'));
                        listUrl.push(oListItem.get_item('PrivacyStatementUrls').get_url()); 

                    }

Is there anyway of getting the whole list of a column straight away instead of having to use the code above

1 Answer 1

0

Use SP.ListItem.fieldValues Property to return a collection of key/value pairs containing the names and values for the fields of the list item.

Example

var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle); 
var items = list.getItems(SP.CamlQuery.createAllItemsQuery());

context.load(items);
context.executeQueryAsync(
function(){

  var rowsData = [];
  var e = items.getEnumerator();
  while (e.moveNext()) {
       var item = e.get_current();

       var values = item.get_fieldValues();
       rowsData.push(values);
   }

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

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.