Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Help with script to require field based on another field

Jenifer Kuntz July 18, 2015

I am trying to make a field required based on another field.  If my Code Reviewer State field is set to Requested I need the Code Reviewer Name to be required.  I am using a validator scripted field.  When I custom script validator it is always allowing the transition.  If I use simple scripted validator it does not allow the transition even if both fields are populated. What am I missing?

TIA

Jenifer

FormField pro = getFieldByName("Code Reviewer State")
FormField ecp = getFieldById("Code Reviewer Name")
 
String vpro = (String) pro.getFormValue()
String vecp = (String) ecp.getFormValue()
 
 
  if (vpro == "Requested") {
              ecp.setRequired(true)
  }else{
        ecp.setRequired(false)
 }

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Mark McCormack _Adaptavist_
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.
October 5, 2015

Converting Jamie's comment to answer so that this question shows as answered:

cfValues['Product Development']?.value != 'Yes' || cfValues['Done Environment']

That will make Done Environment required if Prod Dev is set to Yes.

0 votes
Jenifer Kuntz August 18, 2015

Thank you Jamie! That worked!

0 votes
JamieA
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.
August 18, 2015

cfValues['Product Development']?.value != 'Yes' || cfValues['Done Environment'] That will make Done Environment required if Prod Dev is set to Yes.

0 votes
Jenifer Kuntz August 14, 2015

I also tried this in the condition for a simple script: cfValues['Product Development']?.value == 'Yes' && cfValues['Done Environment']?.value == ' '

0 votes
Jenifer Kuntz August 13, 2015

OK, finally got back to this. This is what I have but it is still not working. Any help would be appreciated. import com.atlassian.jira.issue.Issue import com.opensymphony.workflow.InvalidInputException Issue myIssue = issue; if ((cfValue['Product Development'] == "Yes") && ((cfValues['Done Environment'] == " ")) { invalidInputException = new InvalidInputException("Done Environment is required"); }

0 votes
Jenifer Kuntz July 22, 2015

Ugh, sorry. I will have to try to to write something. I am not a coder, usually just try to find something close and adjust it. Thanks!

0 votes
JamieA
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.
July 18, 2015

The code that you have there is for behaviours... but you mention script fields and validators. The simplest way to do this is with a "simple scripted validator" - what is the code you have for that?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events