Forums

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

Make fileds mandatory using script runner

Teza May 1, 2020

Hello Jira Users,

I need some help on making some fields required on the resolved transition screen using script runner plugin, to be more descriptive when ever the ticket moves from inprogress to resolved there are couple of fields that we would want them to be required. I designed the transition screen and attached it in the workflows but I cant get the script runner to work by making these required. Need help on this ASAP.

We only have ScriptRunner and no other add-ons..

The following are the field types that I would like to make them required on the transition screen:

  • User picker field
  • MultiText field
  • Single Select field
  • Multi Select field
  • Single line field.

 Thanks!

1 answer

1 accepted

0 votes
Answer accepted
Payne
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.
May 1, 2020

You can create a ScriptRunner Simple Scripted Validator with a condition something like the following:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField field1 = customFieldManager.getCustomFieldObjectsByName("Name of Field 1")[0]
String field1Value = issue.getCustomFieldValue(field1)
CustomField field2 = customFieldManager.getCustomFieldObjectsByName("Name of Field 2")[0]
String field2Value = issue.getCustomFieldValue(field2)

return field1 != null && field2 != null

and an error message like "Field1 and Field2 must not be empty when performing this transition."

Teza May 7, 2020

Great, will give it a try. Thanks!

Suggest an answer

Log in or Sign up to answer