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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Script Runner Behaviour Script - Find the project key of a Story's Epic Link

Hi all,

I am trying to find the project key associated with the Epic Link that is linked to a Story using a Behaviour which is mapped to the Epic Link field on Story issue types and using a validation script.


My use case is that I want to restrict a Story from being linked to an Epic which is not in the same project as the Story.  I plan to use the project key related to the Story and Epic issue as our project keys are unique.


I've been able to get the project key related to the mapped Story with the following code:


import com.atlassian.jira.project.Project

Project project = getIssueContext().getProjectObject()
String projectCategory = project.getProjectCategory().getName() as String

String projectKey = project.getKey()


My aim is to do the following to get the Epic's related project key:

1. Get issue key for Epic Link field

2. Create issue object for Epic using above issue key

3. Get project issue from above issue

4. Get project key from above project


My current code attempt is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager

def epicLinkField = getFieldByName("Epic Link")
def epicLinkIssueKey = epicLinkField.getValue().toString()

IssueManager issueManager = ComponentAccessor.getIssueManager()

String epicIssue = issueManager.getIssueObject(epicLinkIssueKey).getProjectObject().getKey()


My errors come after the .getIssueObject().

For debugging, I've set the error on the Epic link field (epicLinkField.setError()) to be random text.   If I chop the last line in the code above to end after getIssueObject, then the the error shows as expected.


As soon as I add any Issue class method after this, either on the same line or on a new line which casts on to the variable epicIssue, the Epic Link error no longer appears.


I assumes this is crashing the script, but I am not told anything in the JIRA admin area unlike when a workflow script validator fails.

The code above works in some workflow validator scripts I have (although a different way to get the key for the Epic Link field), however it is failing here.


I expect that if I can get the project object for the Epic issue, then I can do epicProjectKey = epicProjectObject.getKey() like I've done to get the project key of the mapped Story.


Any help on what I can do?  Thanks








2 answers

Hi All,


I am looking code for same scenario like restrcting users to select epic link from different projects.


Can you share me the complete code to do this?

Hello @Daniel Tsirlin,

I can't get the whole picture - this validator in postfucntion or Behavior script when you changing some fields (on creating/editing screen)?

as I understand,

epicIssue = issueManager.getIssueObject(epicLinkIssueKey)

will work?

try to add logging to be sure:


and don't forget to define your logger.



Hi Ivan,

Before your message I found out that my code works when I hardcode a string representing epicLinkIssueKey and that my issue is getting that value.



def epicLinkField = getFieldByName("Epic Link")
String epicLinkIssueKey = epicLinkField.getValue().toString()

I get the string equalling to "key:<valueOfIssueKey>"

Using this value for getIssueObject() won't work since there is the "key:" at the front.

scriptrunner is telling me that the output of getValue() is an Object type, so i tried epicLinkIssueKey['key'] (before adding toString()) and it doesn't like it.  I tried making my own map and use the same notation for getting keys and it works, so i assume that the Object isn't what I'm expecting.


For now i've decided to make a substring of the output of getValue().toString() to start at index 4, thus it returns just the issue key, however this is quite ugly haha.


I don't exactly know how to use the logger you mentioned, but do you know how I could figure out what sort of object you get from getValue()?  The documentation for scriptrunner seems to be poor at best and doesn't help at all.




Hi @Daniel Tsirlin,

interesting workaround :)


about logging this works for me:

import org.apache.log4j.Logger
import org.apache.log4j.Level

Logger logger = Logger.getLogger("")

logger.debug("Check me in catalina.out")

This should works.

and to get class of object in groovy use:


 Btw, ScriptRunner has a great tool in admin area, called "Script Consle". You able to see result and logs via UI (but I prefer console with tail -f catalina.out)

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events