Requiring Values for Field

Christopher Cannata February 19, 2014

Hello, I am trying to force users to fill in values for a custom field if the value of a different field is set to a certain value.

Example: I have a custom field "Linked Issues". I want users to have to provide a value for this field if they specify the value "Duplicate" in the Resolutions field.

1 answer

1 accepted

0 votes
Answer accepted
Sameera Shaakunthala [inactive]
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.
February 19, 2014

I guess you want to perform this validation when performing a certain workflow transition. You can write a Groovy script validator for this. You need to install Groovy runner plugin for this.

Using Groovy, you can check the values of Resolution and custom field, and then display an error message and prevent status transition.

Alternatively, you can use use Behaviours and Groovy runner plugins together. Behaviours may work in issue edit screen as well. I guess following code will work for Behaviours.

if(!getFieldById("customfield_10000").getValue() && getResolutionObject().getName() == "Duplicate"){
  getFieldById("customfield_10000").setError("Resolution is Duplicate. You must set a value for this field.");
 } else {
         getFieldById("customfield_10000").clearError();
 }

Sameera Shaakunthala [inactive]
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.
February 19, 2014

By that you mean the list of issue links?

So, as per my understanding, if the Resolution is Duplicate, then at least one issue link (probably the duplicated issue) must exist. Am I right?

Christopher Cannata February 19, 2014

I made a mistake, Linked Issues is not a custom field, it is a field provided standard with Jira. I can't get it to work, because I am not sure how to specify it to throw the error if Linked Issues is left blank.

Christopher Cannata February 19, 2014

That is correct. I am trying to force our users to provide at least one issue link.

Sameera Shaakunthala [inactive]
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.
February 19, 2014

You have to have Groovy runner plugin for this.

For the workflow status transition where you need to perform the validation, add a 'script validator' - 'Simple Scripted Validator'. Part of what you need is already there - a bultin line of code. (Has at least one outward duplicate link)

issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate')

If you can change it to something like this, it should work.

issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate') || issue.getResolutionObject().getName() != 'Duplicate'

mdistester2 mdistester2 April 4, 2019

Hi,

I'm new to all these but I'm tasked to do something similar to this.


From what I understand I need something called script runner( which my company has installed) 

I start by going to the workflow that I want to run this on, and add the code above? to the script runner for it to work.

I don't know much about coding and as such I have no clue why I'm getting error while copying said codes above.

Both the long one for behaviour or the short one for the scrip runner

Suggest an answer

Log in or Sign up to answer