Forums

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

We have two custom fields called assessed branch & commit ID.

PRAMOD KUMAR REDDY KASIREDDY
Contributor
March 14, 2022

Actually, we’re having a Custom Filed Name Called “Assessed Branch” (Multi-Select) with values of (Given Below)
1. 19.3
2. 19.11
3. 19.2
4. 20.1
5. 19.10
6. 20.10
7. 18.14
8. 18.51
9. 18.13
10. 16.3
11. 16.9
12. 16.10
13. 20.2
14. 20.3
15. 21.1
16. 21.2
17. 21.3
And 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. 3
16. 9
and 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 emptyCommit ID.pngCommitt-id Filed.pngCommitt-id Production.pngCommitt-id.png

1 answer

0 votes
PRAMOD KUMAR REDDY KASIREDDY
Contributor
March 14, 2022

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def cfMgr = ComponentAccessor.getCustomFieldManager()
import com.atlassian.jira.issue.customfields.option.Option
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.project.Project
import groovy.json.*
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
//def cfMgr = ComponentAccessor.getCustomFieldManager()
// Get the fields by its name
def ab = getFieldByName("Assessed Branch")
def cf = getFieldByName("Commit_ID")

// Get the field values
def branch = ab.getValue() as String[] // Return the multi select values as Array - String[] is an array of Strings
String outcome = cf.getValue()
cf.clearError() // Clear the error message before the validation

def regex = /.*[a-zA-Z0-9]./
outcome.eachLine{

// ======================= Do the validation here
if(it != "||Assessed Branch||Commit ID/Label||"){ // Skip the table header
def 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(", ")) }

}
}
}

Suggest an answer

Log in or Sign up to answer