cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP analytics cloud - How can i filter a story based on the logged in user department

AAad
Explorer
0 Kudos
595

Hi experts,

For my time and attendance report and i have a dimension for userId and another dimension for department name. i want to filter the story or page by the logged in userId department.

i got the logged in user in a variable called loggedInUser.

var loggedInUser = Application.getUserInfo().displayName;

Any idea how to achieve this ?

A.K

SAP Analytics Cloud, analytics designer 

SAP Analytics Cloud 

Accepted Solutions (1)

Accepted Solutions (1)

Venkat99
Explorer

Hi A.K,

One easy way to achieve this is 

1.Created a hidden table which filtered based on user logged in i got from your script function

var loggedInUser = Application.getUserInfo().displayName;

Once this hidden table is filtered you will get 'Department' member which he belongs with this function

var rslt =tab_hidden.getDataSource().getResultSet();
var dept=rslt[0]["Dept"].id;

2.Cretae a input control to filter all relevant widgets in your story with below function

IC_1.getInputControlDataSource().setSelectedMembers(dept);

With this it will filter the story with dept that user is logged in.

 

There are other ways too but i feel this is easy and simple to restrict widgets in story with the required department.

Dept filter.pngThanks,

Venkat

 

 

 

 

AAad
Explorer
0 Kudos

Dear Venkat,

Thanks a lot for your response. some how your solution almost achieved what I need. I have created a model from an excel (userID and departmentName) as columns and gave them like two dummy rows. however, im getting this errorerror.png

Venkat99
Explorer
0 Kudos
show me the script you have written
AAad
Explorer
0 Kudos

This is the simple csv model i used

excelcsv.jpg

and this is the script:

var loggeduserx = Application.getUserInfo().displayName;

Table_3.getDataSource().setDimensionFilter("UserID",loggeduserx);

var tb3rslt =Table_3.getDataSource().getResultSet();

var deptName = tb3rslt[0]["DepartmentName"].id;
InputControl_2.getInputControlDataSource().setSelectedMembers(deptName);

Venkat99
Explorer
0 Kudos
Change syntax as below and try var loggeduserx = Application.getUserInfo().id;
Venkat99
Explorer
0 Kudos
Change syntax like this and try --> var loggeduserx = Application.getUserInfo().id;
AAad
Explorer
0 Kudos

same error, I am getting this error specifically when i add this line:

var deptName = tb3rslt[0]["DepartmentName"].id; 

I am going to accept the original solution as it works with another model.

If you care and have free time, then you can help me with this issue and let me know what other ways can be done in SAC to achieve this.

Thank you

Answers (0)