OpenWGA 7.11 - TMLScript reference


Object:

CollectionResult

Description

Represents an object carrying all resulting data of a document collection.

This is the parent class for objects QueryResult and NavigatorResult which represent collection results of a query or navigator respectively, defining shared functionality of both. A CollectionResult is also created by methods that modify an existing collection result by filtering it or skipping its first results.

Methods that create new CollectionResult objects with modified versions of the original CollectionResult, like filter() and skip(), may be freely cascaded. So you can apply multiple filters and do multiple skips on a collection result.

A CollectionResult is iterable in JavaScript, so it may be used as parameter for the JavaScript function Iterator(). The returned objects are TMLContext objects for the result contents.
Retrieval

CollectionResult.filter()

CollectionResult.skip()

CollectionResult.exclude()

Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Properties and methods
Name Purpose
contains(context)

contains(ctx) takes a WGContext object as parameter and checks if this context is contained in the collection result.

each(function) Applies a function to each element of the collection result.
exclude(context) Filters out the given document from the collection result
filter(function) Applies a filter to the collection result
firstResult Returns the first result document of the collection
firstResultContent Returns the first result document of the collection as WGAPI content object
getPage([offset,] size) Returns a page of result documents
getSingleValue(itemName) Returns the value of an item from the first result document of this collection
groupMap(function [,descending]) This method creates and returns a sorted map keyed by the return value of a user defined function where its value is a list of TMLContext objects evaluating to the same key.
isEmpty() Tests if the result has at last one elements, the current user can read.
map(function) map(function) takes a JS-Function as parameter. This function is called for each result entry with the TMLContext as parameter and must return some value. The return value of map() is a list of all mapped values.
originalResult Returns the original QueryResult or NavigatorResult of this collection result
size Returns the number of result documents in the collection
skip(size) Skips the first documents in the current collection result
Examples

Iterating over a CollectionResult, actually a NavigatorResult here, using a JavaScript iterator. The variable cx is filled with TMLContext objects pointing to the result documents:

for (let cx in Iterator(WGA.nav().children())) {
log.info(cx.TITLE);
}

Same as

WGA.nav().children().each(function(cx){
log.info(cx.TITLE);
})

An example of creating CollectionResults with special modifications in a cascaded way. FIrst we implement a filter to exclude documents being older than 1 month, then we skip the first 10 documents. Finally we retrieve a collection page of 5 documents, being the first 5 documents of the collection which a) are behind the first 10 documents and b) are modified in the recent month:

var theFilter = function (cx) cx.LASTMODIFIED > WGA.modifyDate(WGA.createDate(), "M", -1);
var nav = WGA.nav().children().filter(theFilter).skip(10);
var page = nav.getPage(5);