This version is out of date, covering development from v6.0.0 to v6.6.5. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

TinderboxSix Icon

Look-up tables

Lookup tables, from v6.3.0, allow simple value arrays. This lets some discrete values be mapped onto other values. For example, suppose some notes record the state in which each customer resides. Each state is assigned to a region and it is useful to know the sales region for given customer. Previously, a usual approach would be a set of if() statements:

if($State=="AL") { $Region = "South";} 

However, this is a tedious process if there are many states - it needs a lot of if() statements. Instead, for a Set, List, or String type of Attribute create a list of keyword/value pairs, separated by colons. Each colon-spearated pair is then separated from then next pair by a semi-colon as in a normal Tinderbox list - a semi-colon is not needed after the last pair.

Keyword1:Value1;Keyword2:Value2

$RegionList="AL:South;AK:NorthWest" 

Optionally a default value (for keywords with no match) can be defined:

Keyword1:Value1;Keyword2:Value2;default:North

$RegionList="AL:South;AK:NorthWest;default:North" 

This now allows actions like:

$Region=$RegionList.at($State) 

If the set does not contain the key value, .at() looks for an optional special default key ('default') and returns its value; if there is no default defined or it has no value, .at() returns an empty string.

Realistically, if using lookup tables the lookup value list will be defined in one notes and then reference by all others. Thus the last example above is more likely:

$Region=$RegionList("config").at($State) 

Lookup tables are able to specify several keywords that map to a common value. This is done by separating each keyword with the pipe character '|'. For example:

"Oliver|Micawber|Pip:Dickens;Tess:Hardy;Palliser|Finn:Trollope;default:anon" 

A structural representation of the above example is as follows. The first keyword/value set is in normal text, the second in italics, the third in bold, the default in plain text:

Keyword1-1|Keyword1-2|Keyword1-3:Value1;Keyword2-1:Value2;Keyword3-1|Keyword3-2:Value3;default:anon

The number of keywords in each Keyword/Value set is discrete from other sets in the list.

Keywords are matched on exact, case-sensitive, strings. In the above example "Tess" will return "Hardy" but "tess", "Tes" or "Tessa" would return "anon". If no default had been defined, an empty string "" would be returned instead for the non-matching values.



A Tinderbox Reference File : Actions & Rules : Look-up tables