Assigning values to the dynamic text at runtime – Analytic Application in SAC
How to dynamically assign the measure and dimension value of a table at a particular index to Script variables and binding it with dynamic text.
Step 1 – Create a Table and sort the value column
Add a Table and then sort the value column of it in the descending order as follows.
Step 2 – Create Script Variables
Create two Script variables – ScriptVariable_4 and ScriptVariable_v4. The variable ScriptVariable_4 is a string that can store the particular dimension value and ScriptVariable_v4 is a string variable that can store the particular measure value from the table. Assign some default value to the variables as shown.
Step 3 – Adding Scripts to onInitialization() event
In order to assign the values for the Script variables, add the following script in the onInitialization() event of the main canvas. The script applies filter to a specific dimension value and retrieves the dimension and measure values at a particular index (here we have taken the values at index which will be the highest value as we sorted it in descending order at the first step).
Step 4 – Binding the Script variables to the dynamic text
Create a Text widget for the dimension value to be shown and click on add Dynamic Text under that you can choose the Script variable created for storing the dimension value (here ScriptVariable_4) as shown and also create another text widget for measure value and click on add Dynamic Text under that you can choose the Script variable created for storing the measure value ( here ScriptVariable_v4).
Step 5 – Final Output
Save & Run the application to get the desired output.
Now we will be able to get the values in the text widget dynamically for the measures and dimensions at a specific index in the table.