如何在任务脚本中获取用户名?

发布于 2025-02-08 17:27:14 字数 98 浏览 1 评论 0 原文

我在工作流程中有一个任务,该任务在后端调用了一项服务,该服务以及从任务发送的其他数据等待执行该任务的用户的名称。

如何在用groovy编写的任务脚本中获取用户或用户名?

I have a task within a workflow that invokes a service on the back end that, along with other data sent from the task, waits for the name of the user who executed that task.

How can I get the user or the username in the task script which is written in Groovy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜唯美灬不弃 2025-02-15 17:27:14

您的意思是按用户任务执行脚本任务?假设您想访问从脚本完成以前用户任务的用户的名称,则可以在完成时将用户名存储在过程数据中,如下所示:

grovyprocess.bpmn

You mean a script task following a user task? Assuming you would like to access the name of the user who completed the previous user task from your script, you can store the user name on completion in a process data as shown here:
https://github.com/rob2universe/bpmrun-add-to-dockerimg/blob/e2dd62122b7d006a8a719be96b0a3d043efc9851/configuration/resources/groovyprocess.bpmn#L23

You can then subsequently access the process data in the groovy script task like this:
https://github.com/rob2universe/bpmrun-add-to-dockerimg/blob/e2dd62122b7d006a8a719be96b0a3d043efc9851/configuration/resources/groovyprocess.bpmn#L18

虚拟世界 2025-02-15 17:27:14

您可以按照@rob2universe 提到的任务受让人,也可以使用 excution 对象,始终可以从脚本访问(请参阅“ nofollow noreferrer”> camunda docs )如下:

user = execution.getProcessEngineServices().getIdentityService().getCurrentAuthentication().getUserId()

参见 IdentityService

然后可以将用户名保存到流程变量:

execution.setVariable('username', user)

并访问:

username = execution.getVariable('username')

You could either get the task assignee as mentioned by @rob2universe, or make use of the execution object, which is always accessible from the script (see Camunda Docs), as follows:

user = execution.getProcessEngineServices().getIdentityService().getCurrentAuthentication().getUserId()

See IdentityService.

The username can be then saved to a process variable:

execution.setVariable('username', user)

And accessed:

username = execution.getVariable('username')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文