I have seen many examples, but none of them work in my jira.
both fields are customfields.
the field I am checking is a checkbox, yes/no
if set to yes, I want a text field to be required.
both fields are on a screen that pops up when I click on the done transition.
thankyou for your help with this.
it doesn't do anything and I see this error in the validator dialogue
Cannot get property 'customfield_12718' on null object
What is the exact code you're using and where?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
weird. I posted it, but it didn't show up here. I have this code setup in a validator in my workflow on my done transition.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
FormField checkbox = getFieldById("customfield_12718")
FormField otherfield = getFieldById("customfield_12719")
if (checkbox.getValue() as String == 'yes') {
otherField.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
FormField checkbox = getFieldById("customfield_12718")
FormField otherfield = getFieldById("customfield_12719")
if (checkbox.getValue() as String == 'yes') {
otherField.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
FormField checkbox = getFieldById("customfield_12718")
FormField otherfield = getFieldById("customfield_12719")
if (checkbox.getValue() as String == 'yes') {
otherField.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
FormField checkbox = getFieldById("customfield_12718")
FormField otherfield = getFieldById("customfield_12719")
if (checkbox.getValue() as String == 'yes') {
otherField.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, the code you're using would probably work if you were using a Behaviour. Behaviours have some slightly different methods than everything else and have to have a proper setup and mapping applied to them to work. As a validator it is not going to work though, that is why you are getting errors.
If you want to do that you need to go to Behaviours. Then click "Mapping" and map it to appropriate the project/issue-type etc., and then click "Fields" and add an Initialiser.
You do not have to do this if you think setting up a validator would be easier and still achieve what you need though.
What type of validator are you setting up (a simple scripted validator, a custom scripted validator, etc.)? You need to make a simple scripted validator. There should be an option when you click 'Script Validator' to select this.
Please try this code inside of your validator if you want to that:
cfValues['Checkbox Name']*.value.contains("yes") || cfValues['Text Field Name']
Also, I would like to make the suggestion that you switch to using radio buttons instead of checkboxes unless you need users to have the option to select multiple fields. If you're using a validator.
If you switch to radio buttons you should be able to use this code:
cfValues['Checkbox Name']?.value == 'yes' || cfValues['Text Field Name']
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ty for pointing out the behaviors thing. I had no idea what people were talking about until you said this in the way you said it. Then I realized that I needed to use the addon screen to see behaviors. I am trying to set it up that way now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem! If you have any trouble getting it working let me know.
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
You should be able to accomplish this with a behaviour. A behaviour should be pretty simple as long as I'm understanding the screen you're using it on correctly (a workflow transition screen).
Some simple psuedo code for you:
// get the checkbox, getFieldById(getFieldChanged()) or getFieldById("customfieldId")
// get the other field, getFieldById(customfieldId)
// if checkbox.getValue() as String == 'yes'
// then set the other custom field to required, otherField.setRequired(true)
If you're setting the checkbox value in a preivous workflow step, you should use an initializer function, if not you should use a field behaviour set up to work on the checkbox field.
If you need further help setting this up, let me know. :)
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should also be able to set up a simple scripted validator using something similar to these examples.
Either method should work, it is just based on your preference and whichever you find easier to set up and maintain. :)
Hope this helped you out!
Jenna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the problem with the examples is that they are not complete code. the snippets don't tell me what else I need to make them work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried the following: Add validator -> choose script validator, then entered this code.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
FormField checkbox = getFieldById("customfield_12718")
FormField otherfield = getFieldById("customfield_12719")
if (checkbox.getValue() as String == 'yes') {
otherField.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How about a validator in the workflow?
We also use "Automation for Jira" which allows for If > Then statements that could accomplish a similar function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I want a validator in the workflow. I just need help with the code. I have tried a bunch of things I have found on the network like,
issue.resolutionObject.name != "Fixed" || issue.fixVersions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mine might be part of the JWME addon ........
Try Validator > Regular Expression > Choose field then set expression to somehting like Option [yes]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you, I have that one. but
then what? how do I make the other field mandatory?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You do the same thing for the second field. If the issue doesnt meet the criteria when you try to transition it will spit out an error instead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.