Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira cloud - Scriptrunner - Listener - Appending issue key

AbrahamA
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 Champions.
March 27, 2023

Hello All

In the scriptrunner listener for issue created when I append $${issue.key} it is not working in put function, however if I hard code the key like XXX-152 it works

 

I am trying to update the issue.

What is the correct way to update issue in scriptrunner listener. Please let me know

 

This does not work

def issueKey = issue.key
def result = put('/rest/api/2/issue/${issue.key}') .header('Content-Type', 'application/json') .body([ fields:[ summary: newSummary ] ])

 

This works with hardcoded key


//def issueKey = 'DWS-152'
def issueKey = issue.key
logger.info("${issueKey} or ${issue.key}")
def newSummary = 'Updated by a script'


def result = put('/rest/api/2/issue/XXX-166')
.header('Content-Type', 'application/json')
.body([
fields:[
summary: newSummary
]
])
.asString()
if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}


 

Please let me know.

Abe

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Nic Brough -Adaptavist-
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 Champions.
September 28, 2017

Edit the workflow, open up the transition you want to add it to, and go to the post-functions tab.

Click "add" to add a new post-function and you'll find a list of installed post-functions.  One of them is "scripted post function", which will take you to a second list of options, most of which are "canned scripts".  In that list there is one entry for "write your own", which will take you to the screen where you can enter the script (or path to a saved file)

Deleted user
September 28, 2017

Not really sure where to take it from there. I can add a transition but nowhere does it mention I can run the Script Runner code. And the destination etc. isn't really relevant; i simply want to trigger this code whenever a new task is created?

Nic Brough -Adaptavist-
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 Champions.
September 29, 2017

On the new transition, look at the "post functions" tab, and you'll find the option to add

When you go to add a post-function, one of the options on the list is a "scripted post function".  Select that and click next.

Now you get a list of pre-written scripts, but also one that says "write your own".  Select that and click next.

Now you have a screen where you can enter your script.

If you want this on a new issue, then add the post-function to the "create" transition.

TAGS
AUG Leaders

Atlassian Community Events