Create Documents Programmatically
You have already learned how to create and work with CCH Tagetik Supply Chain Planning Studio documents through the software’s menus and toolbars. This chapter describes how to create and modify documents programmatically using DScripttm.
There are many reasons for creating documents programmatically rather than going through the standard menus and toolbars. For example, you may need to:
- dynamically create and/or manipulate a graph at the end of a data processing routine;
- write a function to color nodes of a tree or set node properties based on node values;
- create a custom graph or table with a combination of properties that are not available through the standard menus; or
- create your own add-in that automatically creates/modifies Studio documents.
This section describes how to programmatically create and manipulate the following CCH Tagetik Supply Chain Planning Studio documents:
- Sheets (Tree Sheet, Text Sheet, Data Table, Report, Diagram);
- Charts (Presentation Table, Graph (2-D), Surface Plot (3-D)); and
- Nodes
Create and Work with Documents¶
The following code fragment will create a new Presentation Table called MyTable and specify its data, vertical legend, and horizontal legend:
var x=inserttable("MyTable"); document[x].data="[[1,2,3],[4,5,6]]"; document[x].vlegend="['Row 1','Row 2','Row 3']"; document[x].hlegend="['Col 1','Col 2']";
The inserttable function in the example above creates a new Presentation Table and returns the name of the new sheet ("MyTable" in the example).
The following are the functions for creating other CCH Tagetik Supply Chain Planning Studio documents:
Functions for Creating SCP Studio Documents
| Function | Creates A New |
|---|---|
| insertdatasheet | Data Table |
| insertdiagramsheet | Diagram |
| insertgraphsheet | Graph |
| insertgraph3 | Surface Plot |
| insertreportsheet | Report |
| inserttable | Presentation Table |
| inserttextsheet | Text Sheet |
| inserttreesheet | Tree Sheet |
You can refer to existing and previously created documents in either of the following ways:
or
Nodes can be referenced and modified programmatically the same way as sheets. However, the process for creating new nodes is a little different.
You create new nodes by defining the nodes in the appropriate namespace. For example, the following code creates a new Tree Sheet that contains a simple Return On Equity (ROE) model.
BuildTree:=( var x=inserttreesheet("MyTree"); document[x].rootnode="ROE"; ROE:=Profit/Equity; Profit:=PBT-Tax; PBT:=100000; Tax:=PBT*34%; Equity:=Assets-Liabilities; Assets:=700000; Liabilities:=250000; )
Note: The BuildTree definition above is inside parenthesis rather braces ({ }). If the code had been placed inside braces, it would create a new block, and, when the function completed, the new nodes would no longer exist in the model scope.