Build.Time and Date Environment
The below code is used to execute a Build process, spanning various other processes.
It is intended that this process is imported as part of the Time and Date Package Download.
Process Code
vb
function pre() {
// This function is called once before the processes is executed.
// Use this to setup prompts.
script.log('process pre-execution parameters parsed.');
var yearFrom = ""
var yearTo = ""
let rootElms = hierarchy.rootElements("Time", "Calender Year List");
if (canBeArray(rootElms)) {//there are elms returned from rootElms
rootElms = JSON.parse(rootElms);
yearFrom = rootElms[0].substring(2);
yearTo = (Number(rootElms[rootElms.length - 1].substring(2)) + 1).toString() //going through to 2026 means we only have months up to 2025 and thus need to add a month to get to what period we want
} else {
var d = new Date();
yearFrom = (d.getFullYear() - 3) + "";
yearTo = (d.getFullYear() + 1) + "";
}
script.prompt("Year From", "yearFrom", yearFrom);
script.prompt("Year To", "yearTo", yearTo);
}
function begin() {
// This function is called once at the start of the process
script.log('process execution started.');
process.execute("System.Dimension.Time", { "dimName": "Time", "yearFrom": yearFrom, "yearTo": yearTo })
process.execute("Dimension.Date", { "yearFrom": yearFrom, "yearTo": yearTo })
process.execute("Mapping.Time to Time.Month to Year Annual", {})
process.execute("Mapping.Time to Time.Month to Prior Month", {})
process.execute("Mapping.Date to Time.Date to Month", {})
process.execute("Mapping.Time to Date.Month to Month", {})
process.execute("Mapping.Date to Date.Date to Prior Year Month", {})
process.execute("Mapping.Date to Date.Date to Prior Year Date", {})
}
function data(record) {
// This function is called once for each line of data on the second cycle
// Use this to build dimensions and push data into cubes
}
function end() {
// This function is called once at the end of the process
script.log('process execution finished.');
}
function canBeArray(input) {
try {
// Attempt to parse the input as JSON
const parsed = JSON.parse(input);
// Check if the parsed value is an array
return Array.isArray(parsed);
} catch (error) {
// If parsing fails, it's not valid JSON, hence not an array
return false;
}
}```