Forums

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

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

Valeria Cruz December 16, 2019

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
Leo
Community Champion
December 17, 2019

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

Valeria Cruz December 19, 2019

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 Champion
December 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