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 get the project key in a ScriptRunner Behaviour

I need to retrieve the current issue's project in a Behaviour groovy script.

I tried using this:

   def myContext = getIssueContext()

but the ScriptRunner interpreter complains that it does not find the method.

I added an import of com.atlassian.jira.issue.context.IssueContext but I still get the same error.

Any idea?

2 answers

1 accepted

0 votes
Answer accepted

I later found out that Will C's answer above does work, but only in some scenarios. In others, the underlyinIssue value is null.

So here is what works for me now:

// Try two ways to get project key in a Behaviour script

String projectKey = null

def projectObj = underlyingIssue?.getProjectObject()

if (projectObj) {  
projectKey = projectObj.key    
else {  
  projectObj = getIssueContext().getProjectObject()  
projectKey = projectObj?.getKey()
  
}

Hi there,

Thanks for replying, can you give me some examples of when underlyingissue is null please?

Just so I dont miss this.

I cannot really tell - I use UserMessageUtil.info() to display debug messages and those popups are displayed only when I refresh the browser tab, so it's hard to tell when exactly they were triggered.

I don't have access to the Jira server so I cannot do a 'tail -f' on the Jira log file(s). When my script was failing, I realized that the projectObj was null, so I added the CYA (:-)) code above.

Maybe, it's null when you create a new issue and non-null when you edit an existing one.

If you have better way to debug Behaviour scripts, please do share.

Thanks again for the original response.

And BTW, in other ScriptRunner scripts that I have (WF validators and post-functions, and script listeners), the issue is always available (event.issue or issue). Only in Behaviour it's problematic.

yea I can understand that the underlyingissue is null before an issue is created.

nope not found a better way to debug behaviours as of yet unfortunately.

def proj = underlyingIssue?.getProjectObject()

This should do the trick 

and it does, thanks

Like Will C likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

301 views 0 2
Read article

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