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