Getting List Items with JSOM - akumina/AkuminaTraining GitHub Wiki

Applies to

Akumina Foundation 3.4 and above

Overview

The GetList method of the Akumina.Digispace.Data.SharePoint object is an addition to the Akumina Framework that provides an easier and cleaner way for developers to retrieve data from lists within SharePoint JSOM. This results in list retrieval code that is easier to write, understand, and modify than its standard JSOM counterpart.

The GetList method requires a request object to be passed to it. It constructs a query and retrieves items from a list based off of the request object's properties.

Example

We assign properties to the request object and let the GetList function build our query

function retrieveListItems() {
    
	var request = {};
	request.listName = "CompanyNews_AK";	
        request.isRoot = true;
	request.selectFields = ["Title","Body","Id"].join(",");
	var exp = (new Akumina.PropertyExpression("Title").EqualTo("Featured In the News_Company Awards"));
	request.queryFilter = (exp);
	
	//Create instance of Akumina.Digispace.Data.SharePoint
	var spcaller = new Akumina.Digispace.Data.SharePoint();

	//Call GetList
	spcaller.GetList(request).then(function (data) {
			//retrieve response from the object returned
		var response = data.response;
			//pass reponse data to Success Handler
		onQuerySucceeded(response);
	}, function (error) {
		onQueryFailed(error.sender, error.args);
	})                
}
    
function onQuerySucceeded(sender, args) {

	var data = {};
	data.Items = [];

	var listItemEnumerator = sender.listItems.getEnumerator();
		
	while (listItemEnumerator.moveNext()) {
		var oListItem = listItemEnumerator.get_current();
		var listItemInfo =
		{
			"ID": oListItem.get_id(),
			"Title": oListItem.get_item('Title'),
			"Body": oListItem.get_item('Body')
		};
		data.Items.push(listItemInfo);
	}

	console.log(data);
}

function onQueryFailed(sender, args) {

	console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

Request Properties

When using the GetList function we need to pass in a request object with specific properties for it to work correctly.

listName

The name of the list from which we want to retrieve data. This is passed as a string. Setting this property is required

Example

var request = {};
request.listName = "Sample_AK";

viewXml

A property where you can designate the entire CAML query for your list request. If you leave this blank a CAML query will be constructed from the other set request property values. It is recommended you use the CAML Query Builder to construct this.

var request = {};
	
var q = new Akumina.CamlQueryCriteria();
q.SelectFields = ["Title","Id"];
var exp = (new Akumina.PropertyExpression("Title").Contains("Akumina"));
q.Filter = (exp);
var query = Akumina.CamlQueryBuilder.Build(q, 3);
        
request.viewXml = query;

selectFields

The fields we are retrieving from the list. This is passed as a continuous string with values separated by commas.

Example

var request = {};
request.selectFields = ["ID", "Title", "AkNumber"].join(",");

isRoot

A boolean value that specifies whether or not the list is on the root site collection.

Example

var request = {};
request.isRoot = true;

isHosted

A boolean value that specifies whether or not the list is on a Hosted web

Example

var request = {};
request.isHosted = true;

hostUrl

The url of the hosting web. This will be passed as a string

Example

var request = {};
request.isHosted = "https://sampledev.sharepoint.com/";

rowLimit

The number of rows to retrieve. You will need to pass a number to this property.

Example

var request = {};
request.rowLimit = 2;

pagingEnabled

A boolean value that specifies whether or not paging will be enabled for the widget.

Example

var request = {};
request.pagingEnabled = true;

orderBy

The order in which we want to retrieve rows based on their fields. This is passed as an array of Akumina.SortDirection objects.

var request = {}
var orderby = [];
orderby.push(new Akumina.SortOrderAndDirection("Title", Akumina.SortDirection.Ascending));
orderby.push(new Akumina.SortOrderAndDirection("AkId", Akumina.SortDirection.Descending));
request.orderby = orderby;

languageId

The id of the content langugage to be retrieved from the list. This is a numeric value and can be retrieved from the UserContext.

Numeric

var request = {};
//language code (Croatian)
request.LanguageId = 1050;

UserContext

var request = {};
//language code from UserContext
request.LanguageId = Akumina.Digispace.UserContext.LanguageId;

additionalProperties

A property where you can store additional properties,

Example

var request = {};
request.additionalProperties = {};
request.additionalProperties.property1 = "Cool Stuff";
request.additionalProperties.property2 = true;

queryFilter

The query filter expression. All values that you would expect to find between the <Where></Where> tags within a query. The Filter is constructed through the use of the Akumina.PropertyExpression object.

Example

var request = {};
var exp = new Akumina.PropertyExpression("Title").Contains("akumina");
var exp2 = new Akumina.PropertyExpression("AkNum").EqualTo(10);
request.queryFilter = exp.Or(exp2);

For more details see the Akumina.PropertyExpression Section

⚠️ **GitHub.com Fallback** ⚠️