Forum Discussion

Rkile's avatar
Rkile
Cloud Apps
08-17-2022
Solved

Filter by loginID

I am curious about the options in locking a filter by a userID login?  If a user logs in, is there a way to limit a dashboard to only showing metrics pertaining to that user via the filters without the user being able to update these filters? 

  • Hi Rkile ,

    Below dashboard script will set email ID of logged-in user as a filter and lock the filter:

    dashboard.on('initialized', function (se, ev) {
    
    	filter = se.filters.$$items.find(el=>el.jaql.title == 'User Email')//Update the name of filter
    	
    	defaultValue = prism.user.email
    
    	filter.jaql.filter = {
       	 	"explicit": true,
        	"multiSelection": false,
        	"members": [
            defaultValue
        	]
    	}
    	
    	filter.locked = true
    	
    	var filterOptions = {
    							save: true,
    							refresh: true,
    						}
    	
    	se.filters.update(filter, filterOptions)
    });

    -Hari

     

  • Here is the updated script. Add emails of admin users to excludeList array.

    dashboard.on('initialized', function (se, ev) {
    
    	filter = se.filters.$$items.find(el=>el.jaql.title == 'User Email')//Filter Name
    	
    	excludeList = ['email1', 'email2']
    	
    	if(excludeList.includes(prism.user.email))
    	{
    		filter.jaql.filter = {
    			"explicit": true,
    			"multiSelection": false,
    			"all":true
    		}
    		filter.locked = false
    	}
    		
    	else
    	{
    		filter.jaql.filter = {
    			"explicit": true,
    			"multiSelection": false,
    			"members": [
    			prism.user.email
    			]
    		}
    
    		filter.locked = true	
    	}
    	
    	var filterOptions = {
    							save: true,
    							refresh: true,
    						}
    	
    	se.filters.update(filter, filterOptions)
    });

    -Hari

7 Replies

Replies have been turned off for this discussion
  • harikm007's avatar
    harikm007
    Data Warehouse

    Hi Rkile ,

    Below dashboard script will set email ID of logged-in user as a filter and lock the filter:

    dashboard.on('initialized', function (se, ev) {
    
    	filter = se.filters.$$items.find(el=>el.jaql.title == 'User Email')//Update the name of filter
    	
    	defaultValue = prism.user.email
    
    	filter.jaql.filter = {
       	 	"explicit": true,
        	"multiSelection": false,
        	"members": [
            defaultValue
        	]
    	}
    	
    	filter.locked = true
    	
    	var filterOptions = {
    							save: true,
    							refresh: true,
    						}
    	
    	se.filters.update(filter, filterOptions)
    });

    -Hari

     

    • Rkile's avatar
      Rkile
      Cloud Apps

      Works perfectly, thank you!

  • Rkile's avatar
    Rkile
    Cloud Apps

    harikm007 - I have a follow up to this.  It is possible to create a list of emails that this rule doesn't apply to? Say there are 3-4 users that can login and view the dash without any filtering taking place? (Like admins).  

    • harikm007's avatar
      harikm007
      Data Warehouse

      Here is the updated script. Add emails of admin users to excludeList array.

      dashboard.on('initialized', function (se, ev) {
      
      	filter = se.filters.$$items.find(el=>el.jaql.title == 'User Email')//Filter Name
      	
      	excludeList = ['email1', 'email2']
      	
      	if(excludeList.includes(prism.user.email))
      	{
      		filter.jaql.filter = {
      			"explicit": true,
      			"multiSelection": false,
      			"all":true
      		}
      		filter.locked = false
      	}
      		
      	else
      	{
      		filter.jaql.filter = {
      			"explicit": true,
      			"multiSelection": false,
      			"members": [
      			prism.user.email
      			]
      		}
      
      		filter.locked = true	
      	}
      	
      	var filterOptions = {
      							save: true,
      							refresh: true,
      						}
      	
      	se.filters.update(filter, filterOptions)
      });

      -Hari

  • I'm sure that harik's script will work beatifully... but Sisense also has Data Security functionality that lets you limit on a row-level in the cube, what data any given user can or cannot see. Wouldn't that also do what you want?

    Iris

    • Rkile's avatar
      Rkile
      Cloud Apps

      Iris,

       

      Do you have a link to more information on this?  Harik's script does work perfectly but I am open to seeing additional options.

      Thanks,

      Ryan