Forums

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

Make a custom field mandatory on resolution based on Priority selection

Marius Pienaar October 18, 2020

Hi Everyone, 

 

I need some help with my code. I want to be able to make a custom field mandatory on resolution based on the priority field.  

Example if I select priority = 1 then Root Cause field must be mandatory but only on resolution. 

 

I've created a behavior to make the field mandatory but I it applies on edits and I only want it on resolution. 

Code:

import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.IssueConstantImpl

def priority = getFieldById(getFieldChanged())
def fieldValue = ((IssueConstantImpl) priority.getValue()).getId()

FormField rootcause = getFieldById ("customfield_18900")

if (fieldValue == "2") {

rootcause.setFormValue(-1)
rootcause.setRequired(true)

}

else if (fieldValue == "10101") {

rootcause.setFormValue(-1)
rootcause.setRequired(true)

}

 

I thought I could do it with a custom script validator on the transition when resolving the ticket but it seems the same syntax doesnt apply when you doing a custom script validator as I get  "Cannot Find matching Method" error for this lines in the code:

 

def priority = getFieldById(getFieldChanged())
def fieldValue = ((IssueConstantImpl) priority.getValue()).getId()

FormField rootcause = getFieldById ("customfield_18900")

 

Can anyone point me in the right direction

 

Thanks 

Marius

1 answer

1 accepted

1 vote
Answer accepted
Leo
Community Champion
October 19, 2020

Hi @Marius Pienaar,

It is pretty easy, just place a condition to check screen name in behaviour

I believe you are using transition screen while resolve/close

below snippet may give you some idea

if(getFieldScreen().name == "Resolution Screen name"){
//Then do your actions here
}

 

BR,

Leo 

Marius Pienaar October 19, 2020

hi @Leo 

 

MAGIC!! Thanks for the advice, worked like a charm! 

 

Marius 

Suggest an answer

Log in or Sign up to answer