Display Username / User ID in visual titles or apply as filters

To access the logged in username to show within visuals or as filters you will have to use a custom style.

The custom style is piece of code (JS to be exact) that runs on initial load of the dashboard, which sets dashboard level parameters (if you are unfamiliar with parameters please make sure to watch the training video module)

The general steps are:

  1. Create custom style using the code at the bottom. (to learn more about custom style creation read: http://documentation.arcadiadata.com/4.3.0.0/#pages/topics/custom-style-site-wide-define-js.html)

  2. Apply the custom style to a filter or visual (which will set global dashboard parameters)
    (learn more by reading : http://documentation.arcadiadata.com/4.3.0.0/#pages/topics/custom-style.html)

  3. Use the parameter syntax in the visual (sub)titles and/or in filter expressions
    image image

Custom Style Code

// Purpose: Set the logged in user's username as a parameter within a visual or application

return function() {
   var f = function() {};
    
    f.version = "1";
    
    f.init = function () {
        // Initialize logged in user as "user" param
        arcapi.sendParameters({"user": arc.globals.username});
            console.log('first load setting user');
    }
    
    f.afterDraw = function() {
        // Reset "user" param on app refresh
        function fetchParams() {
            if (Object.keys(arcapi.getParameters()).length === 0) {
                arcapi.sendParameters({"user": arc.globals.username});
            }
        }
        
        
        fetchParams();
    };

    f.init();
    return f;
}();
1 Like

Please explain the implementation of javascript code in dashboard or visuals in detail as we are not able to see the user name in dashboard when we implement the above code.