Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

Get status of epic while creating story using groovy script via epic link

Abyakta Lenka August 5, 2018

While creating story we put ticket number in EPIC LINK .

I am trying to get the status of epic while creating a story using epic link .

While creating story we put ticket number in EPIC LINK .

if the status of the epic is done then don't allow to create story 

 

Till now this is what i have done :

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issue = issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
def epicLink = issue.getCustomFieldValue(epicLinkCf) as Issue
def st = epicLink.status
log.info("status :"+st)
if (st == 'Done')
{
invalidInputException = new InvalidInputException("Epic is completed please provide Epic which is not Complted")
}

for some reason its not working in the validator .

2 answers

1 accepted

1 vote
Answer accepted
Neta Elyakim
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2018

Try this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issue = issue as Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
String epicLink = issue.getCustomFieldValue(epicLinkCf)

def epicIssue = ComponentAccessor.getIssueManager().getIssueObject(epicLink)
String st = epicIssue.getStatus().name
if (st == 'Done')
{
invalidInputException = new InvalidInputException("Epic is completed please provide Epic which is not Complted")
}

Or use your original script and replace the st line to:

String st = epicLink.status["name"]

Abyakta Lenka August 8, 2018

Perfect . this Resolved my problem

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2018

epicLink.status gives you a status, not a string.

Try

def st = epicLink.getStatus().getName()

instead

Abyakta Lenka August 5, 2018

@Nic Brough -Adaptavist-Screen Shot 2018-08-05 at 8.15.30 AM.pngThis is what i am getting when i am trying 

def st = epicLink.getStatus().getName()

Suggest an answer

Log in or Sign up to answer