Session Variables are an important feature on the Kuika platform that enables the temporary storage of data. They can be used to securely store and manage user session information. These variables allow you to personalize the user experience by storing information such as user ID, session status, and preferred language. In web applications, they ensure that data is preserved throughout the application’s lifecycle.
Opening the Session Variables Screen
Log in to the Kuika platform and open the project you’ll be working on from the Apps screen.
Click the Datasources icon on the top navigation bar.
In the Sources panel on the left, expand the Managed DB heading.
Hover over the Session Variables row, click the three dots (⋯) that appear on the right side, and select Edit.
Defining Session Variables
In the Session Variables screen that opens, variables are listed in a table. To add a new variable, fill in the blank fields in the last row of the table:
Key: The key name that identifies the variable. (Example: user_id, language)
Value: The data the variable will hold. (Example: 12345, English)
Read Only: Determines whether the variable is read-only. When enabled, the variable’s value cannot be changed during the session.
When you fill out a row, a new blank row is automatically added below it. To delete a variable, click the trash can icon to the right of the row.
After completing the definitions, click the SAVE button in the upper-right corner to save.
Data Type Management in Session Variables
When using Session Variables in SQL queries, the data type of the returned data must match the data type expected by the SQL query. You can use the CAST function to convert data types as needed.
In the Datasources module, click the + icon next to the Actions heading in the left panel.
New SQL Action.
Enter a name for the action in the field at the top left.
Write your query in the SQL editor. Example:
Click the CREATE button to save the action.
SELECTCAST(SESSION_CONTEXT(N'user_id') AS NVARCHAR(100)) AS UserId;
This method ensures that the Session Variable is processed with the correct data type.
Testing the SQL Action
To test the defined SQL Action:
Click the Run button in the upper-right corner of the SQL editor to execute the query.
Check the results in the Result tab at the bottom of the editor, and check for error and information messages in the Messages tab.
Verify that the query returns the correct results based on the values from the Session Variable and that the values are dynamically passed to the SQL query.
By following these steps, you can effectively use Session Variables in your applications.