Skip to content

MobileCRM.UI.EntityList.setDataSource

rescocrm edited this page May 15, 2023 · 9 revisions

Sets the entity list data source replacement.

Data source must be set during the document load stage and must not be delayed.

It is used only if the entity view iFrame is marked as data source provider in Woodford.

Arguments

Argument Type Description
dataSource MobileCRM.UI.ListDataSource A data source object implementing the DynamicEntity list loading routine.

This example demonstrates how to provide a custom data source for entity list. It modifies the current entity view fetch and provides the array of DynamicEntity objects that has to be fed into the entity list.

var dataSource = new MobileCRM.UI.ListDataSource();
// loadNextChunk method must be implemented explicitly
dataSource.loadNextChunk = function (page, count) {
	var fetch = this.fetch; // Take a fetch provided for current entity view
	// Specify explicit page and count requested by application (optional - it's pre-set before this method is called).
	fetch.count = count;
	fetch.page = page;
	if (page == 1) {
		// Specify custom filter or link entities.
		// Do it just for the first page!
		// WARNING: Do not add new attributes to the fetch - they will be ignored.
		var filter = new MobileCRM.FetchXml.Filter();
		filter.where("parentcustomerid", "not-null");
		var originalFilter = fetch.entity.filter;
		if (originalFilter && originalFilter.conditions.length > 0) {
			// Combine new filter with original filter which came from the view definition.
			var combinedFilter = new MobileCRM.FetchXml.Filter();
			combinedFilter.type = "and";
			combinedFilter.filters = [filter, originalFilter];
			fetch.entity.filter = combinedFilter;
		}
		else
			fetch.entity.filter = filter; // Set the new filter to fetch entity
	}
	// Execute fetch asynchronously and force the output type DynamicEntities.
	// When the array of DynamicEntity objects is ready, call chunkReady (don't forget to call it in scope of this ListDataSource).
	fetch.execute("DynamicEntities", function (entities) {
		// This is the final place to manipulate with the array of loaded entities before it is passed to the EntityList.
		this.chunkReady(entities); // Callback is called in scope of our dataSource, so we can call it's method chunkReady to pass the data.
	}, MobileCRM.bridge.alert, this);
};
MobileCRM.UI.EntityList.setDataSource(dataSource);
Clone this wiki locally