Pages

Monday, October 28, 2019

Einstein Analytics: Work with Logged in User Detail

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 the 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"
            }

the query above is the same as "query": "SELECT Id, Name FROM User WHERE Id = '!{User.Id}'"

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

                }


Display User Detail

The same method can be used to show the User Name in the dashboard, use a text widget then bind it into the query/step

sample:
"text_1": {
                "parameters": {
                    "content": {
                        "displayTemplate": "Hello [Name]",
                        "values": {
                            "Name": {
                                "field": "Name",
                                "sourceType": "result",
                                "step": "QueryLoginUser_1"
                            }
                        }
                    },
                    "fontSize": 16,
                    "showActionMenu": true,
                    "textAlignment": "left",
                    "textColor": "#091A3E"
                },
                "type": "text"
            }

No comments:

Post a Comment

Page-level ad