Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to throw an error when epic link issues is in closed status

Likhita March 14, 2024

Hi All,

We have a requirement where, when creating an internal defect, users can select any Epic in the Epic Link field, regardless of its status (open, closed, or in progress). However, if a closed Epic is selected, the creation of the ticket should be blocked, and an error should be displayed.

Can anyone provide guidance on how to prevent this and display an error message instead?" 

 

3 answers

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 15, 2024

Hi @Likhita

For your requirement, I suggest using the Server-Side Behaviour for the Epic Link field.

Below is a sample working code for your reference:-

import com.adaptavist.hapi.jira.issues.Issues
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def epicLink = getFieldById(fieldChanged)
epicLink.clearError()

if (issueContext.issueType.name != 'Epic' && epicLink.value) {

def reference = Issues.getByKey(epicLink.value.toString().replace('key:','').trim())

if (reference.status.name == 'Done') {
epicLink.setError('This Epic Is Already Closed')
}
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

When an Epic that has transitioned to Done is selected from the Epic Link field, the Epic Link field will return an error message notifying that the Epic has already been closed.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

Below are a couple of test screenshots for your reference:-

1. The test will be performed using 2 Epic issues, i.e. MOCK-1 and MOCK-2 as shown in the screenshots below. The MOCK-1 Epic status is Done, and the MOCK-2 Epic status is in To Do status.

The MOCK-1 Epic Name is Sample Epic and MOCK-2's Epic Name is Open Epic.

test1.png

test2.png

2. Next, I will try and create a new Story and link it to MOCK-1 Epic which is in the Done status. As expected, the Epic Link returns an error message as shown in the screenshot below.

test3.png

3. Finally, I will try to link the Story to MOCK-2, i.e. the Epic which is in the To Do status. As expected, the Epic Link field is not returning any error as shown in the screenshot below:-

test4.png

 

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

0 votes
Sean Chua _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.
March 15, 2024

Hi @Likhita , I'm not sure if it can be done natively for Jira Data Center, but if you have ScriptRunner for Jira Data Center, then it is definitely possible with the workflows validator.

You can use a simple scripted validator with this sample (ScriptRunner Jira DC - Workflow Validator (If Epic link/parent selected is in status "Done", block issue creation) ). This may not be 100% the same in your instance.

I made it to show me the error under the epic link custom field.
image.png

Hope this helps. If you have an issues with ScriptRunner, please feel free to open a ticket with us in our new Cloud Support Portal .

Regards,
Sean

0 votes
Marc - Devoteam
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.
March 14, 2024

Hi @Likhita 

I think you can use workflow properties but only in case you restrict all edit on the epics that are in Closed status.

You can use the property jira.issue.editable = false on the Closed status and users won't be able to add new issue to closed Epics and they won't be able to edit closed epics either.

Throwing an error message I can't see in this case

Suggest an answer

Log in or Sign up to answer