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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I block a story epic link by a CF in epic? Edited

How can I block a story epic link by a CF in epic?

 

This validation needs to be in issue creation

for example
an issue type Story can only have a epic link if this epic has the custom field 1 = abc

1 answer

1 accepted

0 votes
Answer accepted

Hi @Valeria Cruz,

Below script may give you some idea/reference. I haven't tried this my workflow though, it may require some minor changes 

Try adding in Custom Script Validator in create transition

 

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

def issueManager = ComponentAccessor.issueManager
def epicLink = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Epic Link")

def epic = issue.getCustomFieldValue(epicLink) as String

if(epic){
def issueE = issueManager.getIssueObject(epic);
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Custom Field")
def cfValue = issueE.getCustomFieldValue(cf) as String
if(cfValue == "abc"){
return true
}
else{
throw new InvalidInputException("Invalid Epic Association")
}
}

 BR,

Leo

Tks Leo, its working!!

 

but I need to validate the fields empty too. 'cause we can create story without a epic link too

 

I'm trying to use 

else if(epic == null ){

return true

but doesn't worked

Leo Community Leader Dec 19, 2019

Hey, if you notice my script I already did a validation for epic is empty or not

if there is Epic it does enters for field validation if not. it won't. 

I just missed to add Else part in the bottom. below may fix your issue

if(epic){

  //code written already for field validation if epic mapped

}else{

   return true // if issue created without epic

}

 

BR,

Leo 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,349 views 22 31
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you