Dynamic Filters Based on Logged-in User

In most cases, report filters should remain the same no matter who’s viewing them, and data should be restricted based on user permissions. However, there are times when users should be able to see just the most relevant information based on the logged-in user’s data/groups and changing data permissions is not possible. For example, a report needs to be created only showing the logged-in user’s team data, but they have access to data outside their team. Now, dynamic filters can be created to look at data based on the logged-in user’s personas and groups. 

There are two main use-cases for filtering data based on the logged in user. The first scenario is to display data for the logged in user. This is the simplest example and the easiest to set up as shown below.

The other use-case is to filter a report to groups based on the logged-in user’s personas. This process is more involved but follows a general pattern for setting up. First, the filtering groups need to be identified along with the formatting of said groups. Next, the corresponding user persona IDs need to be identified. Lastly, the filter needs to be set up with the previously found information.

Filter to logged in user

By using a value of -1 in the personIds field you can filter the report to the logged in user. This is helpful if you want to create a report showing the current user's activity.

"personIds": [
-1
]

Identifying Groups to Use in Dynamic Filter

The first step of using dynamic group filtering is to identify the end result of the filter. In other words, what should the report be filtered to? Once that is determined, the group’s custom ID needs to be identified. 

Take a report that should be filtered to the direct reports of the logged-in user. For this example, the group is built in a way that the group’s custom ID is “Direct Reports” followed by the user’s name and resource ID. So, a user that has name “First Last” and resource ID 123, would have a direct reports group custom ID of “Direct Reports First Last 123”.

Finding the User Data

Now that a group has been chosen to be used in the report, the dynamic data needs to be found on the corresponding user. Going back to the example from earlier, the user’s name along with their persona corresponding to their resource ID need to be identified. This data can be found by going to the learner’s profile in the UI or by finding the data in the person object using Watershed’s people API

For the example, the user’s name and the account name for the persona with the homepage of https://example.com/resourceId are needed.

Setting Up the Report Filter

With the group to be used identified and where to find that data on the user, it is time to set up the filter in the report. For this, the below placeholders can be placed in the groupCustomId filter to automatically update to the logged in user’s corresponding information with the format of ${<placeholder>}

Simple Placeholders

The following simple placeholders may be used:

  • user.id 
  • user.customId 
  • user.name 
  • user.displayName

For a simple example, the following filter:

{
 "groupCustomIds": [
  "Group A: ${user.name}"
 ]
}

Would convert to:

{
 "groupCustomIds": [
  "Group A: First Last"
 ]
}

for the user above. 

Placeholders Based on Any Persona

While creating a filter based on the above simple placeholders is the most straightforward, any persona data on the user can be used in the filter. 

To select a persona by pattern-matching on a persona property, the placeholder to include in the filter would look like this:

"${user.personas.match('account.homePage', '<regex>$').account.name}"

This will replace ${...} with the account.name of the current user's persona that an account.homePage that contains a specified regex expression matches, if such a persona exists.

For the example used above, the account.name wanted would be 123 from the persona with homePage of https://example.com/resourceId. For this, the placeholder would look like the following:

${user.personas.match('account.homePage', '^.*/resourceId$').account.name}"

Putting both parts of the filter together would look like this:

{
 "groupCustomIds": [
  "Direct Reports: ${user.name} ${user.personas.match('account.homePage', '^.*/resourceId$').account.name}"
 ]
}

Would convert to:

{
 "groupCustomIds": [
  "Direct Reports First Last 123"
 ]
}
Was this article helpful?
0 out of 0 found this helpful

If you can't find what you need or you want to ask a real person a question, please contact customer support.