Set filter value using token

Hello Helical Insight Team,

I am using Helical Insight version 5.2.2. What I would like to do is to get the profile value by SSO token and set that as a default value of the filter.

Thank You,
Netta.

Hello Netta,

In this document, we will cover how to set user profile values as default dashboard variables dynamically

  1. Create a report with a filter and add the same filter at the dashboard level (a filter that can be used to filter the report data using profile values)

  2. Right-click on an empty space in the dashboard designer, then go to Advanced > JS

image

  1. Inject below script in JS place holder

image

Code :

var profilesData = {{ user | json }};

if (profilesData.profile.some(p => p.profileName === "client_name")) {
    var client_name = profilesData.profile.find(p => p.profileName === "client_name").profileValue;

    if (typeof client_name === "string" && client_name.includes(",")) {
        client_name = client_name.split(",").map(item => item.trim()); // Convert comma-separated string to array
    } else if (!Array.isArray(client_name)) {
        client_name = [client_name]; // Convert single value to array
    }

    setVariable('client_name', client_name);
}

Note1 : The above JS code handles one profile name, “client_name.” If you want to add more, you need to include additional if conditions. You must use the exact profile key name.

Note2 : We have created a profile with the name “client_name”, which contains multiple values.

image

  1. When we open the dashboard with a user having the “client_name” profile, it pre-selects and filters the dashboard data by setting those profile values.

image

In the above snapshot we have passed the profile value via the user role management page. But the same can come directly via SSO token as well.

Thanks You,
Helical Insight Team.