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.
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.
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.
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.
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events