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

12 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
  5. I understand the "Set the Initial Value" part and have used it in my dashboard. But, where to insert/edit the "Set the Initial Value" & "Use the above query result as a filter" queries?
    Since we are not using a List widget for these queries (because we don't want to display the widget as per the scenario). Sorry, I must be asking a very basic question!!

    ReplyDelete
  6. Hello - instead of showing full name, is it possible to only show firstname? I tried "!{User.FirstName}'" but this was undefined. Is it only the 4 fields which are available at runtime? (name, id, rolename, roleid).
    Thanks!

    ReplyDelete