I have created cascading list with two dropdown lists, which created by Dynamic Forms Jira Plugin. But if I fill parent list and not fill child list - my issue anyway create. How I can make both fields of Dynamic Cascading Select are required to prevent the task from being created if the inherited field is empty.
@Егор, привет!
Here's the example for Scripted (Groovy) Validator (JMWE app):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
Issue myIssue = issueObject
CustomField cascadingCF = customFieldManager.getCustomFieldObjectByName('YOUR_FIELD_NAME')
Map cfVal = myIssue.getCustomFieldValue(cascadingCF) as Map
String first = cfVal.get(null)
String second = cfVal.get("1")
if (second != null)
return true
else
return false
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.
Hi @Егор ,
To make both fields of the Dynamic Cascading Select required, you can use a combination of JavaScript validation and Jira's built-in field configuration options. Here's how you can achieve this:
1. Enable the JavaScript validator in Jira:
- Go to Jira Administration.
- Navigate to Issues > Custom Fields.
- Find the Dynamic Cascading Select field and click on "Configure" next to it.
- Under the "Options" section, enable the "Use JavaScript Validator" option.
2. Implement JavaScript validation for the cascading select fields:
- In the JavaScript Validator textarea, write the following code:
function validateCascadingSelect(value, field, issue, errors) {
var parentFieldId = "customfield_XXX"; // Replace XXX with the ID of the parent field
var childFieldId = "customfield_YYY"; // Replace YYY with the ID of the child field
var parentFieldValue = issue.fields[parentFieldId];
var childFieldValue = issue.fields[childFieldId];
if (!parentFieldValue || !childFieldValue) {
errors.push(field.name + " is required.");
}
}
- Replace "customfield_XXX" and "customfield_YYY" with the actual IDs of your parent and child fields, respectively.
3. Save the JavaScript validation code and configure the field:
- Click on the "Update" button to save the JavaScript validation code.
- Make sure the cascading select field is marked as required in the Jira field configuration.
With this setup, when a user tries to create or edit an issue, the JavaScript validator will check if both the parent and child fields have values. If any of them is empty, an error message will be displayed, and the issue will not be created or updated until both fields have valid values.
Obviously, You should test this in a test environment before implementing in Production.
/Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Markus Fredén
JS Validator - its plugin or extension for Jira?
I opened System - Issues - Custom Fields - Configure(my dynamic cascading select). But haven't "Use JS Validation" option
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Markus Fredén
I added validation:
function validateCascadingSelect(value, field, issue, errors) {
var parentFieldId = "customfield_15150"; // Replace XXX with the ID of the parent field
var childFieldId = "customfield_15150-1"; // Replace YYY with the ID of the child field
var parentFieldValue = issue.fields[parentFieldId];
var childFieldValue = issue.fields[childFieldId];
if (!parentFieldValue || !childFieldValue) {
errors.push(field.name + " is required.");
}
}
But when I trying to create issue I have an error:
Steps to reproduce:
1. Go to Issues - Workflows - *my_workflow*
2. Click on step Create - To open
3. Add Validator
4. Scripted (Groovy) Validator (JMWE app) (radio button)
5. Add your code block with change values of id
6. Update
7. Create new task
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Егор ,
My apologies, I was assuming that you had ScriptRunner installed (I'm so used to it) which provides the JS validator feature.
/Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since you have JMWE and not SR you can use the workflow function called "Jira Expression" which accepts JavaScript logic, for example:
!issue.get("customfield_1") || !issue.get("customfield_2")
This expression checks if either of the custom fields (customfield_1 and customfield_2) is empty. If any of the fields is empty, the expression will evaluate to true and the validator will fail.
/Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.