Page Life Cycle: Accessing a List - akumina/AkuminaTraining GitHub Wiki

Applies to

Akumina Foundation 3.4.0.0 and later

Accessing a List

We will create a custom step that retrieves the first value in the Test_AK list.

How to Deploy

  1. Create a custom SharePoint list called “Test_AK”. No additional columns are required. Add one item.
  2. Download digitalworkplace.custom.js from the “/Style Library/DigitalWorkplace/JS” folder within SharePoint
  3. Paste the Code within digitalworkplace.custom.js
  4. Upload the updated digitalworkplace.custom.js to the “/Style Library/DigitalWorkplace/JS” folder within SharePoint
  5. Navigate to a page on your Akumina Foundation site
  6. Flush your cache by clicking on the Akumina icon in the left rail, clicking the refresh icon, then clicking “Refresh All Cache”
  7. Refresh the page. The alert should fire.

List

image 4

Code

var AdditionalSteps = AdditionalSteps || {
}
if ((typeof AdditionalSteps.MoreSteps) === 'undefined') {

    AdditionalSteps.MoreSteps = {

        Init: function () {
			console.log('AdditionalSteps.MoreSteps.Init');  
			var steps = [];
			steps.push({ stepName: "Debug Info", additionalSteps: [{ name: "Access a List", callback: RetrieveFromList}] });
            return steps;
        }
        
    }
}

function RetrieveFromList()
{
	var listName = "Test_AK";
	
	var request = {};
	request.listName = listName;
	request.selectFields = 'Title';
	request.rowLimit = 100;
	
	var spcaller = new Akumina.Digispace.Data.SharePoint();
	spcaller.GetList(request).then(function (data) {
		var request = data.request;
		var response = data.response;
		var listItems = response.listItems;
		
		var items = [];
		var listEnumerator = listItems.getEnumerator();
		var count = 0;
		while (listEnumerator.moveNext()){
			var listItem = listEnumerator.get_current();
			var title = listItem.get_item('Title');
			items.push({ title: title});
		}
		
		alert("Retrieved " + items[0].title + " from the list " + request.listName);
		Akumina.Digispace.AppPart.Eventing.Publish('/loader/onexecuted/');
	
	}, function (error) {
		var args = error.args;
		alert ("Request failed. " + args.get_message() + "\n" + args.get_stackTrace());
		Akumina.Digispace.AppPart.Eventing.Publish('/loader/onexecuted/');
	});
}

Result

image 5

References

To learn how to customize the Page Life Cycle using the Akumina Framework see the following articles: