How to dynamically show views in My Requests widget based on logged in user's role?

Guruvendra J
Tera Contributor

As per client requirement, we added 'Favorite requests' and 'Watchlisted requests' choices along with OOTB 'Open requests' and 'Closed requests'. We would like to show 'Watchlisted requests' option only if logged in user has 'sn_customerservice.case_viewer' role.

Any help on how to show/ hide a choice based on logged user role will be appreciated. Please find attachments.

 

1 ACCEPTED SOLUTION

Dominik Chiaia
Giga Expert

Hello Guruvendra,

 

since the "My Requests widget" is probably a cloned version so that you could add your "Watchlisted requests" Choice you can add a data attribute to the Server Script to check if the user has the required role such as

 

data.hasCaseViewerRole = gs.hasRole("sn_customerservice.case_viewer");

 

and use that in your Body HTML Template to change the line from 

 

<option value="watchlist">{{::data.messages.watchlistedRequests}}</option>

to

<option ng-if="::data.hasCaseViewerRole" value="watchlist">{{::data.messages.watchlistedRequests}}</option>

 

which will change the behavior so that the option for watchlist is only offered if the user has the sn_customerservice.case_viewer role. (or the admin role)

 

I hope that solves your Problem!

 

Best Regards

Dominik

 

View solution in original post

2 REPLIES 2

Dominik Chiaia
Giga Expert

Hello Guruvendra,

 

since the "My Requests widget" is probably a cloned version so that you could add your "Watchlisted requests" Choice you can add a data attribute to the Server Script to check if the user has the required role such as

 

data.hasCaseViewerRole = gs.hasRole("sn_customerservice.case_viewer");

 

and use that in your Body HTML Template to change the line from 

 

<option value="watchlist">{{::data.messages.watchlistedRequests}}</option>

to

<option ng-if="::data.hasCaseViewerRole" value="watchlist">{{::data.messages.watchlistedRequests}}</option>

 

which will change the behavior so that the option for watchlist is only offered if the user has the sn_customerservice.case_viewer role. (or the admin role)

 

I hope that solves your Problem!

 

Best Regards

Dominik

 

Guruvendra J
Tera Contributor

Hi Dominik,

Your response helped me in my requirement. Thank you so much.