Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to define current issue key with groovy script on Scriptrunner

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

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

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

Community Events

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

Events near you