OpenWGA 5.4 - TMLScript reference


Lookup table

Description A lookup table is a collection of objects which are stored under individual keys to access them.

A pair of key and value (the object to store) in a lookup table is named "element".  A key can only be used by one element in a lookup table. A special value in contrary can be contained in many elements if it is stored under differing keys.

To read the value of an element from the table use table.get with the key of the element. To create or update an element with a new value use table.put with key and value as parameters.

Keys and values of a lookup table may technically be any type of object, but mostly trivial objects like strings or numbers are used as they can be easily compared and recreated. String keys are case sensitive. You can store different elements under keys "Key", "key" and "KEY".

To iterate over all existing elements of a table you can use global function WGA.getLookupKeys() to retrieve all its keys, which you then can use to retrieve all element values.

From a Java perspective lookup tables are just the TMLScript view of Java interface java.util.Map


Via many methods, but mainly by:


Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Properties and methods
Name Purpose
table.clear() Removes all elements from the table
table.containsKey(key) Tests if the table contains an element with the given key
table.containsValue(value) Tests if an element with the given value exists
table.get(key) Reads the value of the element with the given key
table.isEmpty() Tests if the table is empty
table.put(key, value) Creates or updates an element of the given key with a new value
table.putAll(table) Adds all elements of the parameter table to this table
table.remove(key) Removes the element of the given key from the table
table.size() Returns the number of elements on the table

This example creates a table and fills it with month numbers as keys, storing the corresponding month name as values:

months = WGA.createLookupTable();
months.put(1, "January");
months.put(2, "February");
months.put(3, "March");

Such a table could be used in WebTML code to lookup month names for numbers (not that these couldn't be automatically generated by date formatting, so this is just for demonstration purposes ;-):

The month is <tml:script expression="months.get(monthnr)"/>