Current User Function

I tried to implement a workflow which needs the current user data object. Unfortunately, the documentation is not detailed enough to describe a simple funtion/workflow to retrieve the current user data object.

1 Like

Achieved this by updating a data record and retrieving the user from the UpdatedBy field.

2 Likes

What a smart workaround!

I am coming to this subject after one year. Is there a better way to do it with the version 2022.9.2 ?
Is there any way to do it without modifying the record ?

With the some events like “onManual”, the variable “invoker” seems to be type “auth.identity”. Is there any way to get the user from it ?

Thank you very much for your help guys !

You can use the invoker variable which hold the UserID of the User to get the User Details using “User Lookup” function in workflow.

3 Likes

Hi guys,

maybe someone can explain how you configured your function?

I’ve also configured a user lookup function with Arguments:
lookup* (ID):
value: invoker (Expression enabled)
target: agent

On testing my workflow, I receive an error:
Test failed: workflow 269709671613333506 step 29 execution failed: cannot cast value *auth.identity to ID (target lookup): unable to create ID: unable to cast auth.identity{id:0x326418c09000003, memberOf:[]uint64{0x3879c0a77000003, 0x3879c0a6c010003}} of type auth.identity to uint64

If I’m changing the value to a static userid “” (recieved from cli: corteza-server users list) the Workflow works successfully.
I’ve also converted the invoker value with Expressions into ID and also tested conversion to uint but both ways doesn’t work.

many thanks in advance.
Pascal

@Lenny ,

Is there no canonical way to obtain the current running user id in a workflow?

Hi,

No, at the moment not.

One note: the running user ID might be different than the ID of the person that triggered the workflow, because the workflow can be “run as”.

That’s what’s meant here by invoker?

Aa, I didn’t know about this invoker variable. That should work then.

I’ve encountered the same error before, and to fix it, I used a block to create and modify variables. I stored the ‘invoker’ variable in another variable of string type, naming it ‘VarID1’; then, I assigned the ‘VarID1’ variable to a second variable I created of ID type, named ‘VarID2’.

Next, I took this ‘VarID2’ variable and used it to perform the user lookup, like this:
User Lookup Block:
lookup*: (ID) VarID2

It worked for me.

`{
  "workflows": [
    {
      "handle": "",
      "enabled": true,
      "meta": {
        "name": "Teste Invoker",
        "description": "",
        "visual": null
      },
      "keepSessions": 0,
      "steps": [
        {
          "stepID": "6",
          "kind": "function",
          "ref": "usersLookup",
          "arguments": [
            {
              "target": "lookup",
              "expr": "VarID2",
              "type": "ID"
            }
          ],
          "results": [
            {
              "target": "VarUser",
              "expr": "user",
              "type": "User"
            }
          ],
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "defaultName": true,
              "id": "6",
              "parent": "1",
              "value": "User lookup",
              "xywh": [
                2880,
                2000,
                200,
                80
              ]
            }
          }
        },
        {
          "stepID": "8",
          "kind": "expressions",
          "ref": "",
          "arguments": [
            {
              "target": "VarID1",
              "expr": "invoker",
              "type": "String"
            }
          ],
          "results": [],
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "defaultName": true,
              "id": "8",
              "parent": "1",
              "value": "Define and mutate scope variables",
              "xywh": [
                2320,
                2000,
                200,
                80
              ]
            }
          }
        },
        {
          "stepID": "12",
          "kind": "expressions",
          "ref": "",
          "arguments": [
            {
              "target": "VarID2",
              "expr": "VarID1",
              "type": "ID"
            }
          ],
          "results": [],
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "defaultName": true,
              "id": "12",
              "parent": "1",
              "value": "Define and mutate scope variables",
              "xywh": [
                2600,
                2000,
                200,
                80
              ]
            }
          }
        }
      ],
      "paths": [
        {
          "parentID": "8",
          "childID": "12",
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "id": "10",
              "parent": "1",
              "points": [],
              "style": "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;",
              "value": null
            }
          }
        },
        {
          "parentID": "12",
          "childID": "6",
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "id": "15",
              "parent": "1",
              "points": [],
              "style": "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;",
              "value": null
            }
          }
        }
      ],
      "triggers": [
        {
          "resourceType": "compose:record",
          "eventType": "onManual",
          "constraints": [
            {
              "name": "namespace.handle",
              "op": "=",
              "values": [
                "Workspace"
              ]
            },
            {
              "name": "module.handle",
              "op": "=",
              "values": [
                "ControleReajuste-CR"
              ]
            }
          ],
          "enabled": true,
          "stepID": "8",
          "meta": {
            "description": "",
            "visual": {
              "defaultName": true,
              "edges": [
                {
                  "childID": "8",
                  "meta": {
                    "description": "",
                    "label": "",
                    "visual": {
                      "id": "14",
                      "parent": "1",
                      "points": [],
                      "style": "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;",
                      "value": null
                    }
                  },
                  "parentID": "4"
                }
              ],
              "id": "4",
              "parent": "1",
              "value": "Compose record - onManual",
              "xywh": [
                2040,
                2000,
                200,
                80
              ]
            }
          }
        }
      ]
    }
  ]
}`