Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,363,057
Community Members
 
Community Events
168
Community Groups

Make a custom field mandatory if resolution equals canceled

I need to make a field called "Reason for Cancellation" mandatory if in the resolution of the problem it selects Canceled. But the script is not doing this function.
If not cancelled, the field must be optional.

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

def resolution = getFieldByName ("Resolution")
def motivo = getFieldByName ("Motivo do Cancelamento")

motivo.setRequired(false)

def selectListValue = resolution.getValue()

if (selectListValue == "Cancelado") {
motivo.setRequired(true)
}

But the script above is not working.

1 answer

0 votes

Hi @Yuri Edward Schulze ,

please try the following code :

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

def resolution = getFieldById("resolution")
def motivo = getFieldByName("Motivo do Cancelamento")

motivo.setRequired(false)

if (resolution.name == "Cancelado") {
motivo.setRequired(true)
}

Hope this helps,

Fabio

Hi @Fabio Racobaldo _Herzum_ 

Using the code you gave me, the following error occurs

erro.png

try with :

  • resolution.value
  • resolution.getValue()

both should work properly.

Ciao,

Fabio

Hi @Fabio Racobaldo _Herzum_ 

Even with the updates you sent me along with the script, they didn't take effect and the validation doesn't take place

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

def resolution = getFieldById("resolution")
def motivo = getFieldByName("Motivo do Cancelamento")

motivo.setRequired(false)

if (resolution.getValue() == "Cancelado") {
motivo.setRequired(true)
}
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

def resolution = getFieldById("resolution")
def motivo = getFieldByName("Motivo do Cancelamento")

motivo.setRequired(false)

if (resolution.value == "Cancelado") {
motivo.setRequired(true)
}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events