Wiki source code of Tutoriel Variables de session

Last modified by jhurst on 2021/04/21 10:01

Show last authors
1 **Session Variables Tutorial**
2
3 Session variables are a special type of substitution variables in DigDash Enterprise. Other types of substitution variables are user variables (**${user.<varname>}**), date variables (**${date.<format>}**) and server variables (**${server.<varname>}**).
4
5 Session variables syntax: **${session.<varname>}**
6
7 Like other variables, they can be used in almost any part of a flow: data model, visualization properties and flow properties.
8
9 They are used (substituted) during a flow and cube refresh.
10
11 This document illustrates a possible usage for the session variables.
12
13 **Summary **
14
15 {{toc/}}
16
17 = Life Cycle =
18
19 The scope of session variables is a user session.
20
21 == Instanciation ==
22
23 It is created once a user logs in, for this and only this session (the value is not shared across different sessions).
24
25 The initial value is an empty string, but if a user variable with the **same name** exists for this user, then the initial value will be the value of the user variable.
26
27 Example:
28
29 A user has a **myvar** attribute defined to "//test//": **${user.myvar}** is "//test//"
30
31 Consequently the initial value of the **${session.myvar}** is "//test//", while the initial value of another variable **${session.myemptyvar}** is an empty string.
32
33 == Value Change ==
34
35 If the session variable value is changed during a session, the change is visible only for this session. Other sessions will keep their own variable values.
36
37 == End Of Life ==
38
39 The variable value is deleted when the session is closed.
40
41 = Usage =
42
43 Session variable can be used everywhere a user variable can be used in a flow, non-exhaustively:
44
45 * Data sources: queries, file paths, row filters, derived measures formulas and filters, targets, groups, etc.
46 * Visualization parameters: axis filters,
47 * Flow parameters: export entries name
48
49 Basically, session variables are very close to user variables in their usage. The difference is that it is easier to temporarily change a session variable value during a user session.
50
51 It makes session variables a powerful tool when coupled with flows and cubes that are refreshed on open.
52
53 The following tutorial will explain how to interactively refresh flows with parameters, using session variables and DigDash Javascript API.
54
55 = Tutorial: Interactive Refresh Of A Flow With Parameters =
56
57 == Dependencies ==
58
59 This tutorial makes use of:
60
61 * Linked data sources paths (aka WLNK)
62 * Scheduling options on a flow and on a data source
63 * The editor widget in Dashboard Editor
64 * DigDash Javascript API method from an hyperlink in a Dashboard
65
66 == Context ==
67
68 In this deployment you have a set of folders, each one containing a CSV file named **data.csv**. All files **data.csv** files are exactly of the same structure but represent different scenarios:
69
70 * Scenario1
71 ** data.csv
72 * Scenario2
73 ** data.csv
74 * Scenario3
75 ** data.csv
76 * etc.
77
78 The set of folders itself is not restricted and can expand in the future.
79
80 You want your users to be able to look at different scenarios metrics (once at a time) in a dashboard page.
81
82 One possible way to do it would be to concatenate all **data.csv** files into one big data source, with a new scenario column. This will create a large cube containing all the scenarios data.
83
84 The drawback is if the data set is very large and/or there are a lot of scenarios. The refresh time can be very long for the concatenated source. And this is not optimal because the users may not look at all scenarios everyday.
85
86 The session variables can help you configuring a data source and flows that will have the scenario name (folder name) as a refresh parameter. Then a scenario is refreshed only on a user's request for that specific scenario.
87
88
89 == Users Configuration ==
90
91 1. Connect to Digdash Enterprise User Management page
92 1. At the bottom of the left column, add a new user parameter named **scenarioVar**.
93 1. Set its default value to "Scenario1".
94
95 //Important~://
96
97 (% class="box warningmessage" %)
98 (((
99 Please note that creating a new user variable is taken into account at user's next login. So if your user is logged in the Enterprise Administrator, and/or Dashboard Editor/Viewer, you must log out and reconnect before continuing this tutorial.
100 )))
101
102 == Data Source Configuration ==
103
104 1. Connect to the Enterprise Administrator. If it was already connected, disconnect and reconnect to take the new user variable **scenarioVar** into account.
105 1. Create a new document server that points to the folders containing all scenarios folders.
106 1. Create a new CSV File data source
107 1. Choose the document server you created for this example
108 1. Add a new document to it: Choose the "new link" option in the new document dialog. Click on Browse to select the source for the link, and choose one of the **data.csv** file.(((
109 The link content should look like this: 12345678|Scenario1/data.csv
110 )))
111 1. Now we want this link to represent not only **data.csv** from Scenario1 but **data.csv** from //any// scenario:(((
112 ~=> Change the link to: 12345678|**${session.scenarioVar}**/data.csv
113
114 //Note//: This will work only if you previously created the user variable **scenarioVar** and set its default value to an existing scenario folder. If there is an error while creating the link, you probably missed the user variable creation in previous paragraph. Please note again that creating a new user variable is taken into account at user's next login.
115 )))
116 1. The **data.csv** file from Scenario1 is loaded and previewed (Scenario1 is the default value for **scenarioVar)**. You can configure your data source as usual.
117
118 //Important~://
119
120 (% class="box warningmessage" %)
121 (((
122 Before finishing the data source configuration, schedule the data source (//Refresh// tab in the second data source panel) to **refresh on open**. You may limit the frequency of the refresh to once a day.
123 )))
124
125
126 == Flow Configuration ==
127
128 Create a new flow using the new data source as usual.
129
130 //Important~://
131
132 (% class="box warningmessage" %)
133 (((
134 Make sure you schedule the flow (//Schedule// tab in the properties dialog of the flow) to **refresh on open**. You may limit the frequency of the refresh to once a day.
135 )))
136
137 == Dashboard Editor ==
138
139 1. Connect to the Dashboard Editor
140 1. Add the new flow on a blank page. It should refresh/display the data generated from Scenario1/data.csv because Scenario1 is the default value you set on **scenarioVar** user variable
141 1. Edit the portlet properties to copy the flow identifier in the clipboard
142
143 Now we want to let the user change the scenario value. For this we are going to create a text field where the user can enter the scenario name he wants to see:
144
145 1. Add a new “Editor” portlet (static content) to the page. This type of portlet is used to add static content to a dashboard page (title, description, images...). Here we are using this portlet to add an interface to change the current scenario.
146 1. Edit the Editor and click on the HTML button to directly edit the editor's HTML
147 1. Add a text field, an OK button and the Javascript logic by typing the following HTML code (//do not forget to set the correct flow ID in the link's javascript below, in place of "FlowId"//):
148
149 {{code language="HTML"}}
150 <input type="text" id="scenarioName" value=""></input>
151
152 <input type="button" value="OK" onclick="ddCtrl.setSessionAttribute('scenarioVar', document.getElementById('scenarioName').value); ddCtrl.refreshFlow('FlowId');"></input>
153 {{/code}}