Dynamic Filtering in SAC using Logged in user details to show organization level data

Estimated read time 6 min read

Introduction :

In SAC a common requirement is to filter data automatically based on the logged-in user. SAC makes this relatively straightforward because the logged-in User ID can be retrieved directly through scripting.

In our scenario, the requirement was slightly different users should not see only their own records, but rather all the records belonging to their organization. To achieve this requirement we need to first get the organization details of the logged in user then pass it as a filter across the story.

This blog will explain how this requirement shall be implemented using scripting in SAC and hidden helper charts.

Business requirement :

The dashboard is used by users from multiple organizations.

So when the user opens the dashboard:

The user information need to be identified.Then we need to find the organization associated with the user.The dashboard should display all the records related to the users organization.User should be able to see the records related to other users of the same organization.

Approach used:

You may think why can’t we directly filter by user ID for this scenario, we could filter the dashboard using the user ID but doing that it would only show the data related to that particular user we won’t be able to show the records of all other users of the same organization.

So to achieve this,

We first get the logged in user ID.Retrieve the organization associated with the user.Apply that organization as filter to the dashboard.In addition to that we have also dynamically populated the dropdown based on the filtered data.

To achieve this we shall use 2 helper charts in the story. These charts will be hidden in the dashboard and will be only used to retrieve data through scripting.

Chart 1 – is used to retrieve the organization associated with the user.

Chart 2 : Retrieves the user belonging to the filtered organization.

Code :

The code is written in the onIntialization event of the SAC story

1. Retrieve the ID of the user and pass it as filter on Chart 1 to retrieve the relevant records.

var1 = Application.getUserInfo().id;
Chart_1.getDataSource().setDimensionFilter(“PR_CREATED_BY”,var1);

2. After applying the filter we retrieve the result set and get the user organization.

var2 = Chart_1.getDataSource().getResultSet();
for (var i = 0; i < var2.length; i++) {
var3.push(var2[i][“Organisation”].id);
}

3. Populate the dropdown

Dropdown_1.removeAllItems();
for (var j = 0; j < var3.length; j++) {
Dropdown_1.addItem(var3[j]);
}

4. Applying the organization filter to the table and retrieving the user based on organization.

Table_4.getDataSource().setDimensionFilter(“Organisation”, var3);
Chart_2.getDataSource().setDimensionFilter(“Organisation”,var3);
var5 = Chart_2.getDataSource().getResultSet();
for (var k = 0; k < var5.length; k++) {
var6.push(var5[k][“PR_CREATED_BY”].id);
}

Therefore through the above approach the user can see the organisation level details.

Output Scenarios :
1. When one user is associated with more than one organization all those organization will get populated in the dropdown and same will be shown in table


2. The dashboard displays all records belonging to the user’s organization, allowing users to view data created by other users within the same organization.

3. Hidden charts that are used to fetch user organization and user id details

 

 

 

​ Introduction :In SAC a common requirement is to filter data automatically based on the logged-in user. SAC makes this relatively straightforward because the logged-in User ID can be retrieved directly through scripting.In our scenario, the requirement was slightly different users should not see only their own records, but rather all the records belonging to their organization. To achieve this requirement we need to first get the organization details of the logged in user then pass it as a filter across the story.This blog will explain how this requirement shall be implemented using scripting in SAC and hidden helper charts.Business requirement :The dashboard is used by users from multiple organizations.So when the user opens the dashboard:The user information need to be identified.Then we need to find the organization associated with the user.The dashboard should display all the records related to the users organization.User should be able to see the records related to other users of the same organization.Approach used:You may think why can’t we directly filter by user ID for this scenario, we could filter the dashboard using the user ID but doing that it would only show the data related to that particular user we won’t be able to show the records of all other users of the same organization.So to achieve this,We first get the logged in user ID.Retrieve the organization associated with the user.Apply that organization as filter to the dashboard.In addition to that we have also dynamically populated the dropdown based on the filtered data.To achieve this we shall use 2 helper charts in the story. These charts will be hidden in the dashboard and will be only used to retrieve data through scripting.Chart 1 – is used to retrieve the organization associated with the user.Chart 2 : Retrieves the user belonging to the filtered organization.Code :The code is written in the onIntialization event of the SAC story1. Retrieve the ID of the user and pass it as filter on Chart 1 to retrieve the relevant records.var1 = Application.getUserInfo().id;
Chart_1.getDataSource().setDimensionFilter(“PR_CREATED_BY”,var1);2. After applying the filter we retrieve the result set and get the user organization.var2 = Chart_1.getDataSource().getResultSet();
for (var i = 0; i < var2.length; i++) {
var3.push(var2[i][“Organisation”].id);
}3. Populate the dropdownDropdown_1.removeAllItems();
for (var j = 0; j < var3.length; j++) {
Dropdown_1.addItem(var3[j]);
}4. Applying the organization filter to the table and retrieving the user based on organization.Table_4.getDataSource().setDimensionFilter(“Organisation”, var3);
Chart_2.getDataSource().setDimensionFilter(“Organisation”,var3);
var5 = Chart_2.getDataSource().getResultSet();
for (var k = 0; k < var5.length; k++) {
var6.push(var5[k][“PR_CREATED_BY”].id);
}Therefore through the above approach the user can see the organisation level details.Output Scenarios :1. When one user is associated with more than one organization all those organization will get populated in the dropdown and same will be shown in table2. The dashboard displays all records belonging to the user’s organization, allowing users to view data created by other users within the same organization.3. Hidden charts that are used to fetch user organization and user id details     Read More Technology Blog Posts by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author