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 |
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.
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, |
lookupAll(columnValues[, lookupOptions]) |
Performs a table lookup using the specified parameters as search criteria and returns all matching rows (subject to an optional limit):
|
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); } } } }