Actually, we’re having a Custom Filed Name Called “Assessed Branch” (Multi-Select) with values of (Given Below)1. 19.32. 19.113. 19.24. 20.15. 19.106. 20.107. 18.148. 18.519. 18.1310. 16.311. 16.912. 16.1013. 20.214. 20.315. 21.116. 21.217. 21.3And One More Custom Filed Name “Commit_ID” is Multi Text Line Filed (WIKI). In that field, We have a table with two columns. one is Assessed Brach and Commit_ID/Label. I have attached a screenshot for reference.
Now the problem is when the users are going select Assessed branch values.For Ex: Assessed Brach Value = 16. 316. 9and Before Transition “Fixed”. in Commit_ID Multi Text filed, the user should Fill the required Commit ID/Label Value for 16.3 and 16.9. It should not be empty. except other values may empty
import com.atlassian.jira.component.ComponentAccessorimport com.opensymphony.workflow.InvalidInputExceptiondef cfMgr = ComponentAccessor.getCustomFieldManager()import com.atlassian.jira.issue.customfields.option.Optionimport com.onresolve.jira.groovy.user.FieldBehavioursimport com.onresolve.jira.groovy.user.FormFieldimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.issue.util.IssueChangeHolderimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.user.util.UserUtilimport com.atlassian.jira.project.Projectimport groovy.json.*import com.atlassian.jira.issue.index.IssueIndexManagerimport com.atlassian.jira.component.ComponentAccessorimport com.opensymphony.workflow.InvalidInputException//def cfMgr = ComponentAccessor.getCustomFieldManager()// Get the fields by its namedef ab = getFieldByName("Assessed Branch")def cf = getFieldByName("Commit_ID")
// Get the field valuesdef branch = ab.getValue() as String[] // Return the multi select values as Array - String[] is an array of StringsString outcome = cf.getValue()cf.clearError() // Clear the error message before the validation
def regex = /.*[a-zA-Z0-9]./outcome.eachLine{
// ======================= Do the validation hereif(it != "||Assessed Branch||Commit ID/Label||"){ // Skip the table headerdef defaultValue = """||Assessed Branch||Commit ID/Label||
|16.3| ||16.9| ||16.10| ||18.13| ||18.14| ||18.51| ||19.2| ||19.3| ||19.10| ||19.11| ||20.1| ||20.2| ||20.3| ||20.10| ||20.12| ||21.1| ||21.0| ||21.2| ||21.3| ||Feature branch| |""".replaceAll(/ /, '')
String firstc = it.trim().split("|")[1] // Get the value from the first column
if(branch.contains(firstc)){ // If the Assessed Branch field values contain the Commit_ID first column value
/* Get the second column value using >>> it.trim().split("|")[2]Check if the second column contains a value >>> it.trim().split("|")[2] ==~ regex */boolean gotValueInSecondColumn = it.trim().split("|")[2] ==~ regex
if(!gotValueInSecondColumn)
{ // If the second column DOEST NOT contain a value // Do something here, e.g., show an error message. cf.setError("You must fill the Commit ID/Label Value for " + branch.join(", ")) }
}}}
It looks like you're new here. Sign in or register to get started.