Make a custom field mandatory if resolution equals canceled

Yuri Edward Schulze September 6, 2022

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
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2022

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

Yuri Edward Schulze September 6, 2022

Hi @Fabio Racobaldo _Herzum_ 

Using the code you gave me, the following error occurs

erro.png

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2022

try with :

  • resolution.value
  • resolution.getValue()

both should work properly.

Ciao,

Fabio

Yuri Edward Schulze September 15, 2022

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