Pages

Monday, October 28, 2019

Einstein Analytics: Filter dashboard based on Logged in User

Set the Initial Value

You can set the initial value of a List widget based on the Salesforce logged in user tokens: user.id, user.name, user.rolename, and user.roleid. At runtime, Analytics retrieves the values of these tokens from Salesforce environment variables—these values don’t come from datasets.

Sample:
"Owner_Name_1": {
                "datasets": [
                    {
                        "id": "0FbB00000000pNNKAY",
                        "label": "Opportunities",
                        "name": "opportunity",
                        "url": "/services/data/v38.0/wave/datasets/0FbB00000000pNNKAY"
                    }
                ],
                "isFacet": true,
                "isGlobal": false,
                "query": {
                    "measures": [
                        [
                            "count",
                            "*"
                        ]
                    ],
                    "groups": [
                        "Owner.Name"
                    ]
                },
                "selectMode": "multi",
                "start": [
                    "!{User.Name}"
                ],
                "type": "aggregateflex",
                "useGlobal": false,
                "visualizationParameters": {
                    "options": {}
                }
            }

Instead of selecting the default "All" value, the dashboard will auto select Owner Name widget with the logged-in user. However, if the logged-in user name does not exist in the query result, the widget will show All.


Filter Query Result

Auto-selection by the logged-in user (as above) does not stop the user to select other users from the list. In some scenarios, we do not show the widget at all, and just need to filter the query by logged-in user:

SOQL query to get user attribute
"QueryLoginUser_1": {
                "groups": [],
                "numbers": [],
                "query": "SELECT Id, Name FROM User Where Name = '!{User.Name}'",
                "selectMode": "single",
                "strings": [],
                "type": "soql"
            }

Use the above query result as a filter
"query": {
                    "measures": [
                        [
                            "count",
                            "*"
                        ]
                    ],
                    "groups": [
                        "Owner.Name"
                    ],
                    "filters": [
                        [
                            "OwnerId",
                            "{{cell(QueryLoginUser_1.result,0,\"Id\").asString()}}",
                            "in"
                        ]
                    ]

                }




ReferenceDynamically Set Initial Selections Based on the Dashboard Viewer




No comments:

Post a Comment

Page-level ad