TM1 client · Walkthrough 3 of 3
Run a process and read its result
You create a small TurboIntegrator (TI) process on SData, run it with a parameter, and check the cells it wrote. Then you run it with a wrong parameter and read why it failed, and delete it.
Before you start
- A client of a TM1 server with IBM's SData sample. Connect and list your cubes shows how to make one. The steps here call it
tm1. - To run a process of your own instead, skip the first step and use its name and parameters.
Steps
Create the process. It has one parameter,
pMonth, and its prolog sets the month's budget to the actual units plus 10%. TM1 saves a process even when its code has errors, so compile it first.// A process that sets a month's budget to its actual units plus 10% ProcessPatch process = ProcessPatch.builder() .name("Budget From Actual") .parameters(List.of(ProcessParameterPatch.builder() .name("pMonth") .value("Jan") .type(ProcessVariableType.STRING) .build())) .prologProcedure( """ nActual = CellGetN('SalesCube', 'Actual', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth); CellPutN(Round(nActual * 1.1), 'SalesCube', 'Budget', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth); """) .build(); // TM1 saves a process even when its code has errors, so compile it first List<ProcessSyntaxError> errors = tm1.processes().compile(process).collectList().block(); if (!errors.isEmpty()) { throw new IllegalArgumentException("The process doesn't compile: " + errors); } tm1.processes().create(process).block();# A process that sets a month's budget to its actual units plus 10% process = ( ProcessPatch.builder() .name("Budget From Actual") .parameters([ProcessParameterPatch.builder().name("pMonth").value("Jan").type(ProcessVariableType.STRING).build()]) .prolog_procedure( "nActual = CellGetN('SalesCube', 'Actual', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth);\n" "CellPutN(Round(nActual * 1.1), 'SalesCube', 'Budget', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth);\n" ) .build() ) # TM1 saves a process even when its code has errors, so compile it first errors = tm1.processes.compile(process) if errors: raise ValueError(f"The process doesn't compile: {errors}") tm1.processes.create(process)// A process that sets a month's budget to its actual units plus 10% var process = ProcessPatch .Builder() .Name("Budget From Actual") .Parameters([ProcessParameterPatch.Builder().Name("pMonth").Value("Jan").Type(ProcessVariableType.String).Build()]) .PrologProcedure( """ nActual = CellGetN('SalesCube', 'Actual', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth); CellPutN(Round(nActual * 1.1), 'SalesCube', 'Budget', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth); """ ) .Build(); // TM1 saves a process even when its code has errors, so compile it first var errors = await tm1.Processes.CompileAsync(process).ToListAsync(); if (errors.Count > 0) { throw new ArgumentException("The process doesn't compile: " + string.Join("; ", errors.Select(e => e.Message))); } await tm1.Processes.CreateAsync(process);// A process that sets a month's budget to its actual units plus 10% const process = ProcessPatch.builder() .name("Budget From Actual") .parameters([ProcessParameterPatch.builder().name("pMonth").value("Jan").type(ProcessVariableType.String).build()]) .prologProcedure( "nActual = CellGetN('SalesCube', 'Actual', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth);\n" + "CellPutN(Round(nActual * 1.1), 'SalesCube', 'Budget', 'France', 'S Series 1.8 L Sedan', 'Units', pMonth);\n", ) .build(); // TM1 saves a process even when its code has errors, so compile it first const errors = await tm1.processes.compile(process).toArray(); if (errors.length > 0) throw new Error("The process doesn't compile: " + JSON.stringify(errors)); await tm1.processes.create(process);Run it. Give the parameters by name. TM1 answers when the process ends, with how it ended:
// Parameters by name; TM1 waits until the process ends to answer ProcessExecuteResult result = tm1.processes() .executeWithReturn("Budget From Actual", Map.of("pMonth", "Feb"), ODataQuery.none()) .block(); System.out.println("Status: " + result.processExecuteStatusCode().json());Output
Status: CompletedSuccessfully# Parameters by name; TM1 waits until the process ends to answer result = tm1.processes.execute_with_return("Budget From Actual", parameters={"pMonth": "Feb"}) print(f"Status: {result.process_execute_status_code}")Output
Status: CompletedSuccessfully// Parameters by name; TM1 waits until the process ends to answer var result = await tm1.Processes.ExecuteWithReturnAsync("Budget From Actual", new Dictionary<string, object?> { ["pMonth"] = "Feb" }); // The status as TM1 names it in its JSON Console.WriteLine($"Status: {result.ProcessExecuteStatusCode}");Output
Status: CompletedSuccessfully// Parameters by name; TM1 waits until the process ends to answer const result = await tm1.processes.executeWithReturn("Budget From Actual", { pMonth: "Feb" }, ODataQuery.none()); console.log(`Status: ${result.ProcessExecuteStatusCode}`);Output
Status: CompletedSuccessfullyCheck what it did. Read the two cells:
String mdx = "SELECT {[actvsbud].[actvsbud].[Actual], [actvsbud].[actvsbud].[Budget]} ON COLUMNS FROM [SalesCube]" + " WHERE ([region].[region].[France], [model].[model].[S Series 1.8 L Sedan]," + " [account1].[account1].[Units], [month].[month].[Feb])"; Cellset cellset = tm1.cellsets() .execute(mdx, ODataQuery.none().expand(Cellset.CELLS, cells -> cells.select(CellsetCell.VALUE))) .block(); System.out.println("Actual: " + cellset.cells().get(0).value()); System.out.println("Budget: " + cellset.cells().get(1).value()); tm1.cellsets().delete(cellset.id()).block();Output
Actual: 1526 Budget: 1679mdx = ( "SELECT {[actvsbud].[actvsbud].[Actual], [actvsbud].[actvsbud].[Budget]} ON COLUMNS FROM [SalesCube]" " WHERE ([region].[region].[France], [model].[model].[S Series 1.8 L Sedan]," " [account1].[account1].[Units], [month].[month].[Feb])" ) cellset = tm1.cellsets.execute(mdx, ODataQuery.none().expand(Cellset.CELLS, lambda cells: cells.select(CellsetCell.VALUE))) print(f"Actual: {cellset.cells[0].value}") print(f"Budget: {cellset.cells[1].value}") tm1.cellsets.delete(cellset.id)Output
Actual: 1526 Budget: 1679var mdx = "SELECT {[actvsbud].[actvsbud].[Actual], [actvsbud].[actvsbud].[Budget]} ON COLUMNS FROM [SalesCube]" + " WHERE ([region].[region].[France], [model].[model].[S Series 1.8 L Sedan]," + " [account1].[account1].[Units], [month].[month].[Feb])"; var cellset = await tm1.Cellsets.ExecuteAsync(mdx, ODataQuery.None().Expand(Cellset.Fields.Cells, cells => cells.Select(CellsetCell.Fields.Value))); Console.WriteLine($"Actual: {cellset.Cells![0].Value}"); Console.WriteLine($"Budget: {cellset.Cells[1].Value}"); await tm1.Cellsets.DeleteAsync(cellset.Id!);Output
Actual: 1526 Budget: 1679const mdx = "SELECT {[actvsbud].[actvsbud].[Actual], [actvsbud].[actvsbud].[Budget]} ON COLUMNS FROM [SalesCube]" + " WHERE ([region].[region].[France], [model].[model].[S Series 1.8 L Sedan]," + " [account1].[account1].[Units], [month].[month].[Feb])"; const cellset = await tm1.cellsets.execute( mdx, ODataQuery.none().expand(Cellset.Fields.Cells, (cells) => cells.select(CellsetCell.Fields.Value)), ); console.log(`Actual: ${String(cellset.Cells![0]!.Value)}`); console.log(`Budget: ${String(cellset.Cells![1]!.Value)}`); await tm1.cellsets.delete(cellset.ID!);Output
Actual: 1526 Budget: 1679Read why a run failed. Run it again with a month the
monthdimension doesn't have. TM1 doesn't refuse the run: the process runs to its end, the cell functions fail, and the run ends with errors. It writes them to an error log, which the result names when you ask for it.// A month that isn't in the month dimension: TM1 runs the process, which fails ProcessExecuteResult result = tm1.processes() .executeWithReturn("Budget From Actual", Map.of("pMonth", "Febr"), ODataQuery.none().expand(ProcessExecuteResult.ERROR_LOG_FILE)) .block(); System.out.println("Status: " + result.processExecuteStatusCode().json()); // A run with errors writes a log, which the result names ErrorLogFile log = result.errorLogFile(); if (log != null) { System.out.println(tm1.logs().errorLogContent(log.filename()).block()); }Output
Status: HasMinorErrors Error: Prolog procedure line (1): Invalid key: Dimension Name: "month", Element Name (Key): "Febr" Error: Prolog procedure line (1): error repeats 1 times# A month that isn't in the month dimension: TM1 runs the process, which fails with_log = ODataQuery.none().expand(ProcessExecuteResult.ERROR_LOG_FILE) result = tm1.processes.execute_with_return("Budget From Actual", parameters={"pMonth": "Febr"}, query=with_log) print(f"Status: {result.process_execute_status_code}") # A run with errors writes a log, which the result names if result.error_log_file is not None: print(tm1.logs.error_log_content(result.error_log_file.filename))Output
Status: HasMinorErrors Error: Prolog procedure line (1): Invalid key: Dimension Name: "month", Element Name (Key): "Febr" Error: Prolog procedure line (1): error repeats 1 times// A month that isn't in the month dimension: TM1 runs the process, which fails var result = await tm1.Processes.ExecuteWithReturnAsync( "Budget From Actual", new Dictionary<string, object?> { ["pMonth"] = "Febr" }, ODataQuery.None().Expand(ProcessExecuteResult.Fields.ErrorLogFile) ); Console.WriteLine($"Status: {result.ProcessExecuteStatusCode}"); // A run with errors writes a log, which the result names if (result.ErrorLogFile is { } log) { Console.WriteLine(await tm1.Logs.ErrorLogContentAsync(log.Filename!)); }Output
Status: HasMinorErrors Error: Prolog procedure line (1): Invalid key: Dimension Name: "month", Element Name (Key): "Febr" Error: Prolog procedure line (1): error repeats 1 times// A month that isn't in the month dimension: TM1 runs the process, which fails const result = await tm1.processes.executeWithReturn( "Budget From Actual", { pMonth: "Febr" }, ODataQuery.none().expand(ProcessExecuteResult.Fields.ErrorLogFile), ); console.log(`Status: ${result.ProcessExecuteStatusCode}`); // A run with errors writes a log, which the result names const log = result.ErrorLogFile; if (log) { console.log(await tm1.logs.errorLogContent(log.Filename!)); }Output
Status: HasMinorErrors Error: Prolog procedure line (1): Invalid key: Dimension Name: "month", Element Name (Key): "Febr" Error: Prolog procedure line (1): error repeats 1 timesA process that calls
ProcessError, or fails in a way TI can't go on from, endsAbortedinstead.Delete the process.
tm1.processes().delete("Budget From Actual").block();tm1.processes.delete("Budget From Actual")await tm1.Processes.DeleteAsync("Budget From Actual");await tm1.processes.delete("Budget From Actual");
Next
- Run TI code once without saving it as a process, with the process service.
- Schedule processes as chores.
- Step through a process line by line with the debugger.
More walkthroughs
- Connect and list your cubes: Connect to TM1, check the connection, and list the cubes on the server.
- Read and write cells: Read values from a cube with MDX, write a value, and read it back.