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?"
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:-
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.
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.
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:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.