How to get the current user using ScriptRunner Jira cloud and update a field using /rest/api/2/issue

Rajeev Joshi June 27, 2022

I am trying to update a field based on the current user using Script Runner Jira cloud as a post function of a workflow transition.

The script contains

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

This returns the current user, I can use this to update a field using

def resp = put("/rest/api/2/issue/${issue.key}")
.queryString("overrideScreenSecurity", true)
.queryString("overrideEditableFlag", true)
.header("Content-Type", "application/json")
.body(updateDoc)
.asObject(Map)

The problem is that if the script is run as "current user", /rest/api/2/myself returns the current user, but the put call to /rest/api/2/issue/$(issue.key) fails, due to security/admin

nERROR: TSVCM-540: Connect app users with \"admin\" permission and Forge apps acting on behalf of users with ADMINISTER permission can override screen security."

However, if I run the script as ScriptRunner add-on the /rest/api/2/myself returns Script runner add on and not the current user that is executing the transition resulting in post process and the put(/rest/api/2/issue/${issuekey} executes without errors

So, how do I get current user and update a field using the put function.

4 answers

0 votes
Fayaz Abdul
Contributor
April 9, 2024

@Rajeev Joshi Did you solved this issue??

0 votes
Jay Nelson December 28, 2023

The situation I ran into for this was similar, however I used the ID of a user with Admin to then apply to a different user so that it ran as that "Super user" instead of the user on screen.

0 votes
Joaquin Fernández Morales
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 15, 2022

Hi @Rajeev Joshi 

 

This error is because the user does not have the permission scope to do the transition. If you referred to the documentation here, I mean, the required permissions are: Browse projects and Edit issues project permission for the project that the issue is in

 

This means that the initiating users do not have enough permission. You may also refer to the documentation here for the Scopes, it has described all the permissions for each scope. You cannot use overrideScreenSecurity to overwrite administrator permission. 

 

I hope it helps. 

0 votes
Kántor Tibor
Contributor
July 7, 2022

@Rajeev Joshi 

I'm not an expert with jira and scriptrunner cloud, however this may shed some ligh on your problem with screen security:
https://community.atlassian.com/t5/Jira-questions/Problem-with-overrideScreenSecurity/qaq-p/602226

Rajeev Joshi July 7, 2022

@Kántor Tibor Thank you for your reply.  The ticket you shared, suggests that only Jira admins can override screen security, but I would rather not provide all users/approvers Jira admin privileges.  Hence I am looking for an alternate solution.  Thanks for your response though.

Suggest an answer

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

Atlassian Community Events