How to define current issue key with groovy script on Scriptrunner

Rika Mandasari March 21, 2021

Hi, 
I have a piece of code on Scriptrunner post function Jira workflow;

if (elite.status == 201) {

final customfieldID = 'customfield_10289'
final newFieldValue = 'Success'
put("/rest/api/2/issue/ITS-53")
.header('Content-Type', 'application/json')
.body([
fields: [
(customfieldID): newFieldValue
]
]).asString()
} else {
final customfieldID = 'customfield_10289'
final newFieldValue = 'Fail'
put("/rest/api/2/issue/ITS-53")
.header('Content-Type', 'application/json')
.body([
fields: [
(customfieldID): newFieldValue
]
]).asString()
}

 

I want to define the issue key (ITS-53) as the current issue key that I run when I transition the current issue key and so the post function (scriptrunner) works.

how to replace the hardcoded issue key to the current issue key?

 

Thanks

1 answer

1 accepted

3 votes
Answer accepted
Ram Kumar Aravindakshan _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.
March 21, 2021

Hi Rika,

If you are using the Post-Function, you should use the Issue's key variable, i.e. (issue.key), to dynamically set the current issue key.

To see which keyword you can use, click on the question mark symbol as shown in the image below:-

post_function1.png

Once the question mark symbol is clicked, you will be shown the in-build variables as shown in the image below:-

image_2021-03-22_134336.png

So, in your code, instead of using:

put("/rest/api/2/issue/ITS-53")

you could use:-

put("/rest/api/2/issue/${issue.key}")

 

I hope this helps to answer your question. :)

 

I am looking forward to your feedback.

 

Thank you and Kind Regards,

Ram

Rika Mandasari March 21, 2021

Thanks Ram,

 

Its working perfectly

Suggest an answer

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

Atlassian Community Events