Skip to main content

Create conditions based on user session data

You may want to customize your application's behavior based on the pages a user has visited or the filters they have selected. You can achieve this by storing values in the user session temporarily. You can then use those values in conditions applied to activities, widgets, and/or datasets to control the path of the activity logic or the data that is displayed.

For example, you can use values stored in the user session to:

  • Show prices in the relevant currency. You might want to change the currency in which you display prices based on whether the user accessed your application via a .com or .nl domain, or according to an option the user selected on the homepage. You can store the currency selection in the user's session and then reference that value in conditions applied to widgets and datasets.
  • Persist a filter option. If a user has filtered a list to show only orders they have created, you may want to apply the same filter by default as they navigate to other related pages in your application. You can create an activity and accompanying template widget that allows the user to switch a toggle from "All orders" to "My orders", storing the relevant value in the user's session each time a user submits the activity. You can then add conditions to other widgets and datasets that filter the data based on the value in the user's session.
  • Allow users that have not logged in to generate a quote or make a reservation. You might want to allow visitors to your site to plan a trip or find out how much something will cost without having to log in first. Make the activity that creates an Order or Booking case available to unauthenticated users, and store the case ID in the user's session. You can then allow unauthenticated users to retrieve the details of the quote or the reservation as long as they remain active on your site. If the user then logs in to their account, you can record the Order or Booking case ID in an attribute on their User case so they can complete the process or return to it later.
Tip:

Values stored in the user session are only retained while the current user remains active. This makes it ideal for customizing your application temporarily. If you want values to remain available when a user logs in again in future, store them in attributes on the User case.

Add values to the user session

To add values to the user session, you must define both a custom key and the value you want to store for that key. When you want to use the value from a user session in a condition, you use the key to identify it.

You can store values in the current user session in several ways:

  • Mappings: Add a mapping to the Activity designer to copy a value from various sources including a field on the activity form, an attribute on the current case, the case metadata, or an inline template.
  • Context: Add a context block to the Activity designer to specify a fixed value or define a value using an inline template.
  • Platform context: Add a value to the user session based on conditions that are applied to all users that access your application. For more information, see Platform context.

Once you have stored values in the user session, those values remain available until the user logs out, their session times out due to inactivity (by default after 30 minutes; configurable from My Grexx), or the value is overwritten by writing a different value to the same key.

Tip:

You can check the values stored in custom user session keys using Developer Tools. From any of your application's DTAP environments, press CTRL + ALT + S and then select User > Session.

Apply conditions based on user session values

When you add a condition to an activity, a widget, or a dataset, you can use an inline template to retrieve the values stored in the current user session. For example, you might create a custom user session key to record the date range selected by a user when viewing a report, and then apply conditions to widgets on other views to filter the data that is displayed based on the user's previous selection.

To compare the value stored in the user session to another value using a condition:

  1. Add a condition to an activity, widget, or dataset.
  2. For one side of the condition, set the input to Inline template (or Template when adding a condition to a widget).
  3. In the Inline template/Template field, enter user.User-session and then click the blue text to configure the User session template function.
  4. In the Key field, enter custom. followed by the name of the key. For example, if you defined a key called orders, enter custom.orders.
  5. Configure the rest of the condition as normal.

When the user starts the activity or opens a page or view, the condition is evaluated using the value currently stored in the user's session, and the activity behavior or the data displayed is adjusted accordingly.

For more information about adding conditions, see Apply conditional logic to activities, Configure pages and views, and Configure datasets.