How can I use Groovy Script to get an issue id in a post function? issue.getId() returns null Edited

I'm sure I'm overlooking something simple, as getId() seems to be exactly what I should need.  I've tried issue.getID(), getKey(), etc, to no avail.

 

import groovy.sql.Sql
import java.sql.Driver
import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.component.ComponentAccessor
/* I've tried with and without this declaration as well
Issue issue = issue
*/
// All of these return null. I need to retrieve the id for use in a SQL query later in the script. log.error("id: " + issue.getId()) // returns null log.error("key: " + issue.getKey()) // returns null log.error("number: " + issue.getNumber()) // returns null log.error("issue: " + issue) // returns the Summary field of the issue

Log results

2017-04-06 15:07:37,332 ERROR [workflow.ScriptWorkflowFunction]: id: null
2017-04-06 15:07:37,332 ERROR [workflow.ScriptWorkflowFunction]: key: null
2017-04-06 15:07:37,332 ERROR [workflow.ScriptWorkflowFunction]: number: null
2017-04-06 15:07:37,332 ERROR [workflow.ScriptWorkflowFunction]: issue: sdfsadfasd

1 answer

1 accepted

I'm an idiot.  The reason it was returning null is because the Custom Script post-function was being called before the "Creates the issue originally" post-function.  Re-ordering the post-function calls resolved this.

Hopefully this saves someone else some time in the future.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,241 views 14 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot