ScriptRunner for JIRA Cloud Scripted Fields Get Current User

gencaysyn January 19, 2021

Hi,

I need to get the current user to change the scripted field's content by the current user's group. Some groups should see the raw version of data and some groups should see the calculated version.

I tried this code:

def response = get('/rest/api/2/myself').asObject(Map)
assert response.status == 200

def currentUsername = response.body.displayName

But this response returns the script runner as a user and returns currentUsername as "ScriptRunner for Jira". Is there any other way to get the current user in scripted field. 

1 answer

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

Hi Gencasysn,

I can confirm that Scripted Fields are always run as the ScriptRunner Add on User as they are loaded and calculated when an issue is loaded.

This means if you need to have a calculated field where the user who runs the script is the user who updates the issue that you will need to use a Script Listener and configure this to be run as the Initiating User in order for it to get the current user who changed content on the issue.

Regards,

Kristian

gencaysyn January 19, 2021

Hi Kristian,

I need to show this field on the view screen. This means that I can not trigger any event. Actually, I can do it with ScriptRunner Behavior but this feature is not available for cloud. In other words, this field should be seen in view screen and it should change by user's group.

Regards,

Gençay

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2021

Hi Gencay,

I can confirm in the cloud version of ScriptRunner that the closest thing you can do is to have a script listener which updates a Jira field as mentioned above and this field can be shown on the view issue screen.

Unfortunately, this is the closest you will be able to get your requirement inside of Jira Cloud due to the fact that Behaviours is not available in the cloud version and due to how Scripted Fields work in the cloud version as explained above.

However, if you would like to have the ability to choose to run a Script Field as the Initiating User then I would ask you to raise a request for this in our public backlog located here so that our product owner can see that this a feature which would be valuable to your organisation.

Regards,

Kristian

Like gencaysyn likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events