In many scenarios—such as showing user-friendly month names based on coded values from a model dimension (e.g., “001” = “April”)—you may want to map coded values to meaningful text descriptions.
This mapping logic can be implemented using object literals (i.e., dictionaries or lookup tables).
var monthMap = {
"001": "April",
"002": "May",
"003": "June",
"004": "July",
"005": "August",
"006": "September",
"007": "October",
"008": "November",
"009": "December",
"010": "January",
"011": "February",
"012": "March"
};
// Define a test variable for a sample month code
var MONTH_NUMBER = "003";
// Output the corresponding month name from the mapping
console.log(monthMap[MONTH_NUMBER]); // Outputs: June
Code language: JavaScript (javascript)
Explanation of Logic:
Mapping Declaration:
The monthMap object acts as a lookup table, where each key is a string-formatted month number, and each value is the corresponding month name.
Variable Assignment:
MONTH_NUMBER holds a sample value you want to translate (e.g., “003” represents June)
Value Retrieval:
monthMap[MONTH_NUMBER] fetches the mapped value (e.g., “June”) using the key “003”.
Notes:
The keys must be strings (e.g., “003” not 003) because object keys in JavaScript are string-based.
In SAC scripting, this technique is useful when you:
Retrieve coded dimension values and want to display user-friendly labels in a text widget.
Need to create manual translations or re-labelling of non-intuitive IDs or codes.
If implementing this in SAC, you could use .applyText()
to display this mapped result in a Text_1 widget:
Text_1.applyText(“Selected Month: ” + monthMap[MONTH_NUMBER]);
