Can we set a custom field as mandatory based on other custom field value ?

Sys Admin February 26, 2014

Can we set a custom field as mandatory based on other custom field value ?

For example - "Work Around" customfield should be set as mandatory for "NON Blocker" value of Criticality Customfield but NOT for "Blocker" value of Criticality Customfield

For your info -

Criticality field value - 11131

Non-Blocker Value - 11305

Blocker Value - 11306

Work Around field value - 11134

Also please note - both the fields are in diferent screen. Criticalit field is in create issue screen and Workaround field is in next transition screen

Please provide us the configuration code if required as I am not expert in developing Jira codes

Regards

Sumit Mitra

5 answers

1 accepted

0 votes
Answer accepted
David G February 26, 2014

You can do this, but it requires:

Here is a high level explanation so you can get an idea of what is needed.

After the issue is created, we are going to create a second transition with the same name and screen, and have it go to the exact same status. In effect, we're going to create a transition where the Workaround field is required, and a duplicate transition where it is not. And, we are going to use the Conditions to hide one of the 2 transition buttons based on the value of what is entered in the Criticality custom field.

How To:

Because you did't list the status or transition names, I'm just going to use [ Create -> Open -> In Progress ] for this example. For the transition name, I'm going to simply call it "Start".

  • From Create -> Open, the Criticality field is set based on your comment.
  • From Open -> In Progress, you hit a transition button called "Start". This will display a screen where the "Workaround" field will be set to required, or not, based on the Criticality value.
  • We are going to set one transition to display and not require Workaround, only if Criticality = Blocker
  • We are going to set the 2nd transition to display and require Workaround, only if Criticality = Non-Blocker

Steps:

  1. Open your workflow designer.
  2. Create an additional transition from Open -> In Progress, and label it "Start" to match the original. If JIRA complains about the duplicate name, then make it "Start " with a space at the end.
  3. Set the transition screen to be the same screen the original "Start" transition is using.
  4. NOTE: From here on out, I will refer to the transitions as "Start 1" and "Start 2" so we can keep them separate.
  5. Open the Conditions view on Start 1
  6. Click Add Condition, select Script Condition (a feature of Script Runner Plugin), click Add
  7. Click on Simple Scripted Condition
  8. A list of links will display below, Click on "Has custom field value equal to"
  9. This will populate a quick code snippet in the field above
  10. Change 'SomeCustomField' to 'Criticality' (include the ' ' single quotes)
  11. Change 'Some Value' to 'Blocker' (again, include the ' ' single quotes)
  12. Click Add button at the bottom
  13. Start 1 transition button will now only display if Criticality = Blocker
  14. Open the Conditions view on Start 2
  15. Click Add Condition, select Script Condition, click Add
  16. Click on Simple Scripted Condition
  17. Click on "Has custom field value equal to"
  18. Change 'SomeCustomField' to 'Criticality' (include the ' ' single quotes)
  19. Change 'Some Value' to 'Non-Blocker' (again, include the ' ' single quotes)
  20. Click Add button at the bottom
  21. Start 2 transition button will now only display if Criticality = Non-Blocker
  22. Open the Validators view on Start 2
  23. Click Add Validator, select Fields Required, click Add
  24. Select Workaround, click Add >> button
  25. Click Add button at the bottom
  26. Start 2 transition now requires Workaround
  27. Publish Workflow

We just did 2 things

  • Set 2 transitions to display/hide based on value of Criticality
  • Set the 2nd transtion that shows when Criticality = Non-Blocker, to require Workaround field

Please note that setting a field as required through the Validator transition does not display a required asterisk, but it is actually required.

Sys Admin February 27, 2014

We have followed your above mentioned steps. But after configuring this both the transitions were hide for Blocker and Non-Blocker Criticality values.

I am explaining our requirements again -

We have configured two workflow transtion in aparticular workflow.

1) production incident occurred

2) Initial analysis started

We have a customfield in "production incident occurred" transition namely "Critical" and the field ID is 11131. There are 2 values in this field namely "Blocker" and "Non-Blocke". The value ID of "Blocker" is 11306 and value ID of "Non-Blocker" is 11305.

Now we have a custom field namely "Work Around" in "Initial Analysis started" transition. The field id is 11134

We need to set "Work Around" field required in "Initial Analysis started" transtion if anyone choose "Non-Blocker" from "Criticality" field in "production incident occurred" transition and if anyone choose "Blocker" from "Criticality" field in "production incident occurred" transtion then "Work Around" field should be optional in "Initial analysis Started" transtion.

For this purpose I have configured Behaviour script for "Work Around" field. Please find the script below -

FormField priField = getFieldById("customfield_11131")
FormField priJustField = getFieldById("customfield_11134")
String Criticality = (String) priField.getFormValue()
if (Criticality == "11306") { // 11306 is Blocker
priJustField.setRequired(false)
}
else{
priJustField.setRequired(true)
}

But after configuring the above code both "Work Around" field set required for both "Non-Blocker" and "Blocker" value. Could you please inform if anything wrong in my code or we need to use any alternative way

3 votes
Chander Inguva
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.
December 16, 2015

Hi All,

            I have a working code to set Behaviour on a parent field and based on the field values other field can be marked as mandatory or not at time of creating issue.

 

  • Here, parentField is referred to main field and where the Behaviour has to be added
  • childField is referred as the Field which is dependent on parentField Options
def childField = getFieldByName("XYZ")
def parentField = getFieldById(getFieldChanged())
def selectedOption = parentField.getValue() as String

if ((selectedOption == "abc") || (selectedOption == "def") || (selectedOption == "123") || (selectedOption == "111"))
{
  childField.setRequired(true)
}
else
{
  childField.setRequired(false)
 }

 

Hope this helps

 

Regards

Chander Inguva

Sys Admin December 17, 2015

Hi Inguva, Thank you for your help. I have some confusion - My parent field name is "Call Type". In this field there is a value namely "New Machine Required". If I choose "New Machine Required" Value from parent field "Call Type" the child field namely "Instance Type" should be marked as mandatory. I can not able to understand how can put those values in your script. Could you please update your script with the values which I have mentioned ? Thanks in advance

Sys Admin December 20, 2015

Hi Inguva, Sorry to bother you again. Is there any update

nidhis July 8, 2016

Hi,

 

I tried the above both codes, but its showing for any value in the parent field, another field as mandatory.

Ratna Kumar Lekkala June 30, 2017

Chander,

Did you add it as a validation script or initializer script? did you add this to the parent field or child field? Or did you add it to the workflow action?

 

Sebastian Gomez May 5, 2021

This Behavior template worked for me. thank you @Chander Inguva 

0 votes
M. P. April 15, 2015

Hi @David G, @Nic Brough [Adaptavist]

we have almost similar issue.

In our case CustomFieldB is an cascading custom field that includes Option A and Option B, this Options has several Values. So we need CustomFieldA to be required, when CustomFieldB = OptionA.ValueB, while performing Close transition.

However we do not need this Close tranistion to be hidden. Therefore I didn't added the condition.

I have tried the simple script by adding cfValues['CustomFieldB'] == 'OptionA.ValueB' as a validation to the Close transition and additionally I have added "Field Required" Validator for CustomFieldA. But it doesn't work.

When I'm performing "Close" transition the CustomFieldA is required as CustomFieldB is set up to OptionA.ValueB, but when the CustomFieldA is filled, it still askes me to fill it in. Why ? How can I fix it ?

THanks in advance!

 

0 votes
Wei Qiao April 5, 2015

Hi, is it possible to achieve that by writing the groovy script??? I am also facing this issue but it would be nicer if we can achieve this by a script. 

0 votes
Sys Admin March 5, 2014

This issue is solved by using Condition "Value Field". I have create 2 different transtion as you suggested and add "Criticality" value "Non-Blocker" and Set "Work around" as required in One Transition and "Criticality" value "Blocker" in another Transition. After that problem is resolved

Suggest an answer

Log in or Sign up to answer