Building a Customdataload Callback: Overview - akumina/AkuminaTraining GitHub Wiki

Overview

In this document we will go through examples of using the Digital Workplace widget framework to build widgets using the Generic List Control (GLC) Customdataload callback type. The Customdataload callback type is a GLC callback that allows us to access the widget properties within the callback function. This allows us to customize how the GLC retrieves data, for example, retrieving data from multiple lists, lists on different sites, or even third party data.

Widget Manager

Widgets that use Customdataload callbacks are instances of the Generic List Control Widget. We can create an instance by finding the GenericList Control within the Widget Manager and clicking its “View Instances” button. image 1 This will take us to the Manage Widget Instance View. Here we will click "+ Add Widget Instance". image 2 In the WidgetProperties Panel, find the callbacktype property. Type in customdataload. Click “Save & Exit”. This widget instance is now configured to use the customdataload callback. image 3

dataloadproperties

Within the WidgetProperties Panel there is a property called dataloadproperties. Here we can define custom properties to pass to our customdataload callback. This is crucial in customizing the data retrieval of the callback. Custom properties and their respective values should be defined in the following fashion:

{'<PropertyName1>':'<Value>','<PropertyName2>':'<Value>',…,'<PropertyNameX>':'<Value>'}

image 4

Callback

When building a Customdataload callback our code will follow the form below:

function CustomDataLoadCallback(listRequest, def) {
    var me = this;	
    var context = new SP.ClientContext();

var dataProperties = JSON.parse(listRequest.dataLoadProperties.replace(/'/g, "\""));
var customParam = dataProperties.customparam;

//Retrieve any other necessary data

    context.executeQueryAsync(
		Function.createDelegate(me, function () { Successhandler(listRequest, def); }),
		Function.createDelegate(me, function (sender, args) { Errorhandler(listRequest, def); })
	);
	
}

function Successhandler(listRequest, def) {
	var result = {};

	//Add data to result properties
	//These properties will be bound to the template
	
	def.resolve({ response: result });
   
}

function Errorhandler(listRequest, def) {
	def.reject();
}

function CustomDataLoadCallback(listrequest, def)

This is the callback form that the customdataload callback looks for.

listrequest

The GLC properties can be accessed directly from this object.

def

This is the jquery deferred object. It is included with every customdataload callback. It is resolved or rejected based on the retrieval of data.

var dataProperties = JSON.parse(listRequest.dataLoadProperties.replace(/'/g, """));

Here is where we retrieve our dataloadproperties value as an object.

context.executeQueryAsync

Our customdataload callback requires us to fire a request that has a success and a fail case.

function Successhandler(listRequest, def)

In our success handler we assign our data to appropriate Mustache Icons for our template. Think of this as where we would do the job of a standard GLC callback.

var result = {}

The object we will bind to the template

def.resolve({ response: result });

We resolve the deferred object, which sends the result object to be bound to the template.

function Errorhandler(listRequest, def)

In our error handler we will reject our deferred object and implement proper error handling

def.reject();

We reject our deferred object.

References

See the articles below for more on the Customdataload callback

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