We have large number of transitions in a workflow and each transition pops up a screen prompting the user to check the box next to a set of conditions. These are things like "Has the Manager Approved", "Has the CFO Approved" etc. I use a multicheckbox for these.
I would like to stop a user form transitioning if all the checkboxes are not checked. I am using script runner and am pretty sure I could add a large number of cfValues['Field'][0] == "Has the Manager Approved", etc etc.. However this is very cumbersome and a nightmare if any of the fields are changed. Is there a simpler Validation function I can use that would work? Something like.. Field.AllValues are 'Yes'. I have Script Runner and Behaviours installed.
Thank you :)
Instead of multiple single checkboxes use muli checkbox custom field. So you can check all checks in a collection.
If not applicable fetch all CF check boxes and compare their names to a mask/template and only validate those that match. Be sure to name CF's properly
def customFieldManager = componentManager.getCustomFieldManager() def customFields = customFieldManager.getCustomFieldObjects(issue) customFields.each {cf -> if (cf.name =~ 'Approved by' ) { //do your stuff here } }
This seems like a really good approach.
I am assuming I would put a version of this script in the Script-Runner Validator for the transition. If all my custom fields have a similar name I would look for that name so the script would be reusable on multiple transitions without having to re-write it.
And... that's where my knowledge stops.
I know that the "//do your stuff here", I need to ensure all the checks are checked, and, that if they are, I need to return true (I think). Otherwise I return false and the step fails validation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just looked at the issue again. I was surprised there is no single checkbox custom field type.
This means you either have one multi checkbox field for each approval checkbox or ONE multi checkbox field with options for each approval.
Let me know what is the case and I'll look for a solution.
I suggest you learn some Jira API using this page https://developer.atlassian.com/static/javadoc/jira/5.0/reference/com/atlassian/jira/issue/fields/CustomField.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I presently have 15 MultiCheck box fields each with a number of options that all need to be checked. The field names are all predictable and named similarily, so a regex to find the field would work. The pseudocode would be something like this:
for each customfield that contains "Check_" do {
If all options in customfield are not null {
return true
} else {
return false // Do not validate
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use .getValue(issue) method to get a collection of selected options
i did not have time to learn API to get all options for a multiselect filed to compare available options to selected. It might be easier to add all options from all relevant custom fields to one collection then compare it to desired set/collection of options. I might be able to provide a snippet later
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def customFieldManager = componentManager.getCustomFieldManager() def customFields = customFieldManager.getCustomFieldObjects(issue) def values = [] customFields.each {cf -> if (cf.getName() =~ "Check_" && cf.getCustomFieldType().getName() == "Multi Checkboxes") { values += cf.getValue(issue)*.toString() } def validChecks = ['CFO', 'CTO'] //add all your required options here return values.containsAll(validChecks) ? true : false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can achive by using javascript as follows
<script type="text/javascript"> var selected = new Array(); $(document).ready(function() { $("input:checkbox[name=customfieldID]:checked").each(function() { selected.push($(this).val()); }); if(selected.length <5){ alert("enter your message here.."); return false; } }); </script>
you have to do little bit modifications as per your requirement and your jira version.
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.
I have tried to use the following line in the simple validator box:
Collections.frequency(Arrays.asList(cfValues['CustomField']),null) == 0
But it does not quite work as I hoped.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I could make a custom field for each checkbox. However that would be an insane number of custom fields. With the additional workload of if I want to add an element to the list I need to edit a screen and add the field. This is something I am willing to do if there is no elegant validator solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think, not simpler but more elegant and maintenance-free, is to get the list of option values for that custom field and make sure they're all present. I would write a condition in groovy, rather than using the "simple scripted condition", if that's what you're using. Don't have time to write it for you, if I get a chance, I'll post.
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.