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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def proj = underlyingIssue?.getProjectObject()
This should do the trick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
and it does, thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.