Field Required Validator or Behavior

Rakesh Jajper June 22, 2022

Hi Team,

 

I want few fields required upon closing of ticket via scriptrunner or JSU, as this 2 add-ons we have.

So When some one click Close request and if Field A = ABC then it should check if field X & Y is not empty. Trying on various ways but couldnt succeed.

Trying Field Required Validator (Scriptrunner) but no luck, behavior will not fit as I need this on workflow transition. This is what I am using on behavior side but thats also not working.

Please help here for this one to make it work on workflow transition and what should I use.

import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
 
def FieldA = getFieldById("customfield_15600")
FormField TrAMSFunctionalArea = getFieldById("customfield_15702")
String FieldA = (String) FieldA.getValue()
 
if (FieldA.equals("ABC") {
FieldX.setRequired(true)
FieldY.setRequired(true)
}
else {
FieldX.setRequired(false)
FieldY.setRequired(False)
}

2 answers

1 vote
Dam
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2022

Hi Rakesh, 

Here is a documentation that explain how to do it with apps such as JSU or Scriptrunner... do not code for that, there are existing validator with JSU or Scriptrunner ;) 

https://confluence.atlassian.com/jirakb/make-custom-fields-required-in-a-workflow-transition-in-jira-server-691011903.html

I hope this helps ;) 

Cheers,
Dam.

0 votes
Tansu Akdeniz
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2022

Hi @Rakesh Jajper 

Do all the fields exist in Close transition screen? If not, getFieldById("customfield_xxxxx") doesn't work in bhv.

Also, I couldn't see FieldX and FieldY definition in your code.

I suggest you use setHelpText() within the code to see variable values step by step.

As I see, you use same variable "FieldA" twice in the code. Change to:

String FieldAVal = (String) FieldA.getValue()
Please also check this doc.

Suggest an answer

Log in or Sign up to answer