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

10 comments:

  1. How I get the currently logged in UserID in dataflow ,after that need to implement further logic

    ReplyDelete
    Replies
    1. Do you mean user who schedule the dataflow?

      Delete
  2. No.I need to fetch the details of records of current loggedin user as well as Account Hierarchy related records. Means any parent Account or related Account records in my dataset .So I need to get Loogedin userID so that I can full AccountID and from that Account I can full parent and related Accounts IDs.

    ReplyDelete
    Replies
    1. Not sure what you want regarding current login user versus dataflow/dataset.
      I think your need is mostly on security predicate

      Delete
    2. I have requiremnt like , if community portal user loggedin he can able to see his account records as well as his parent and subborinate account records.based on those records I need to some calucaltions.Thats why, I was asking how I can bring current loggedin userid in dataflow.

      Delete
    3. For sure it is not in the dataflow, but security predicate in dataset, you can add flatten node in dataflow for that

      Delete
  3. Hi Im using list widget and want to setup loggedIn user it is not working for one user. But if I clone the dashboard then it works for that user.

    ReplyDelete
  4. Is it possible to set the initial value of a list selector to be All if a user is a certain group/profile but otherwise be the logged in user? Something along the lines of the "Me and My Team" style filters in Standard Reporting?

    ReplyDelete
    Replies
    1. probably you can create a field to check if the user are part of the certain profile and use that field as start, instead of the real Name field

      Delete

Page-level ad