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.