Need to make a custom field mandatory when other value of a custom field is changed

Aravind Koushik Gobburu February 20, 2024

Hi Team,

I having two custom fields Criteria and Reason for change. In edit issue when Criteria value changes user needs to be specify the reason as mandatory why they are changing the Criteria. For this can anyone help me to write a groovy script. I tried with the following code but it's not working.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def criteriaField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Criteria" }
def reasonForChangeField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Reason for Change" }

def criteriaOldValue = issue.getOriginalValue(criteriaField)
def criteriaNewValue = issue.getCustomFieldValue(criteriaField)

if (criteriaOldValue != criteriaNewValue) {
// Criteria value changed, make Reason for Change mandatory
if (!issue.getCustomFieldValue(reasonForChangeField)) {
issue.setCustomFieldValue(reasonForChangeField, "Default value or handle as needed")
}
}

1 answer

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2024

Whatever it is that you're coding with that API is incorrect and it cannot do anything that you are describing.

 

For dynamic forms there are Behaviours:

 # https://docs.adaptavist.com/sr4js/latest/features/behaviours

 

And these use a very different code syntax to read/update the forms.

Also several good examples could be found here: https://library.adaptavist.com/search?library-content%5BrefinementList%5D%5Bplatforms%5D%5B0%5D=dataCenter&library-content%5BrefinementList%5D%5Bfeature_names%5D%5B0%5D=behaviours

 

Suggest an answer

Log in or Sign up to answer