The LookupTable object represents an immutable lookup table in Rhapsody. It cannot be instantiated directly by the user. The only mechanism to retrieve this table is via the getLookupTable() global function. It directly maps to the LookupTable interface in the Rhapsody API.

Function Description
getLookupTable(tableName)

Retrieves the lookup table with the specified name returning a LookupTable JavaScript object. This function maps directly to the LookupTableService.getLookupTable() method in the Rhapsody API.

Methods

Method

Description

lookup(values[, resultColumnName])

Performs a table lookup using the specified parameters as search criteria and returns only the first matching row. A row in the table is matched if all the provided values match the table values in their specified columns in the same row.

  • values - the values used to match a row. This is either a single ColumnValue object if the match is only on a single column, or an array of ColumnValue objects to search by multiple values.
  • resultColumnName (optional) - used when you only want the value in one column to be returned, rather than the entire row.

An exception is thrown if the lookup fails or any of the column names are invalid. It returns null if no match is found which is indicated as a lookup failure in Rhapsody IDE. If a match is found, it returns the value in the desired column, if the optional parameter, resultColumnName, is provided; otherwise, it returns the values for all the columns in the row.

lookupAll(columnValues[, lookupOptions])

Performs a table lookup using the specified parameters as search criteria and returns all matching rows (subject to an optional limit):

  • columnValues - the values in JSON format used to match a row. For example:

    [{columnName: "translated_system", value: "CDC"}, {columnName: "internal_code", value: "A"}]
  • lookupOptions (optional) - can be one or more of the following options:
    • returnColumns (optional) - a list of column names that their values are included in the results. Used when you only want the value in one column to be returned, rather than the entire row.
    • sortColumns (optional) - a list of column names to be used to define a specific order of the results (the sort order is case-sensitive). For each column, results are returned in ascending order by default. The results can be returned in descending order by setting the desc object property to true, for example:

      [{columnName: "text", desc:true}]
    • limit (optional) - the maximum number of results to be returned. By default, a maximum of 100 results is returned. It can be configured globally via rhapsody.properties file:

      # Maximum rows returned from lookupAll. By default this is 100.
      # LookupTable.defaultReturnedRowsLimit=100

lookupAll() is not supported for the Mapper filter; use RhapsodyTableLookup() instead.

Examples

internal_code

text

translated_code

translated_system

pl

Polish

2115-4

CDC

fj

Fijian

2101-4

CDC

ir

Irish

2113-9

CDC

sc

Scottish

2116-2

CDC

The following example uses the optional parameter resultColumnName to look up a value in the translated_code column:

// Replace the internal code with the CDC coding system
for (var i = 0; i < input.length; i++){
    var next = output.append(input[i]);
    
    var msg_race_id = next.getField("PID.Race[0].Identifier");
    
    // Get the table
    var lookupTable = getLookupTable("race_cs_replace");
    
    // Create the search parameter
    searchFor = new Array();
    // Look for the internal_code column and value in the message
    searchFor[0] = new ColumnValue("internal_code", msg_race_id);
    // But only return rows where the translated_system is CDC
    searchFor[1] = new ColumnValue("translated_system", "CDC");
    
    // Only look up a value from the translated_code column
    var result = lookupTable.lookup(searchFor, "translated_code");
    
	if (result != null) {
		next.setField("PID.Race[0].Identifier",result);
   	}
   	
   	// When the code is translated, change the coding system string too!
   	next.setField("PID.Race[0].NameOfCodingSystem","CDC");
} 

The following example looks up the internal_code and translated_system and returns the first matching row in the race_cs_replace table:

// Replace the internal code with the CDC coding system
for (var i = 0; i < input.length; i++){
    var next = output.append(input[i]);
    var msg_race_id = next.getField("PID.Race[0].Identifier");
    
    // Get the table
    var lookupTable = getLookupTable("race_cs_replace");
    
    // Create the search parameter
    searchFor = new Array();
    // Look for the internal_code column and value in the message
    searchFor[0] = new ColumnValue("internal_code", msg_race_id);
    // But only return rows where the translated_system is CDC
    searchFor[1] = new ColumnValue("translated_system", "CDC");
    
    // Perform lookup
    var result = lookupTable.lookup(searchFor);
    
    // Received the whole row from the table (all columns and values)
	if (result != null) {
    	// Iterate through the returned list of ColumnValue objects
    	for (var i = 0; i < result.length; i++) {
    		if (result[i].columnName == "text") {
    			next.setField("PID.Race[0].Text",result[i].value);
    		}
    		if (result[i].columnName == "translated_code") {
    			next.setField("PID.Race[0].Identifier",result[i].value);
    		}
         }
    }
    // When the code is translated, change the coding system string too!
    next.setField("PID.Race[0].NameOfCodingSystem","CDC");
} 

The following JavaScript excerpt looks up the internal_code and translated_system and returns a maximum of 10 matching rows in the race_cs_replace table:

// Replace the internal code with the CDC coding system
var resultRows = lookupAll("race_cs_replace", 
                      [{ columnName: "translated_system", value: "CDC" }], 
                      { returnColumns: [ "text" ], sortColumns: [ { columnName : "text", desc : true } ], limit:10 } );
 

if (resultRows != null) {
    for (var i = 0; i < resultRows.length; i++) {
        // Iterate through the returned list of ColumnValue objects
        for (var j = 0; j < resultRows[i].length; j++) {
            if (resultRows[i][j].columnName == "text") {
    			next.setField("PID.Race[i].Text",resultRows[i][j].value);
    		}
    		if (result[i][j].columnName == "translated_code") {
    			next.setField("PID.Race[i].Identifier",resultRows[i][j].value);
    		}
        }
    }
}