Hey,
I have a custom checkbox field with multiple options and I want to see if one specific checkbox was checked or not.
Right now I am using the indexOf() function to see if the value is in the smart-value list, which works, it returns -1 if it's not checked and a different number if it is checked, but my condition using the .eq() function does not work and I am not sure why.
{{#if(issue."My custom checkbox field".value.indexOf("Option 1").eq(-1))}}
Option 1 was NOT checked
{{/}}
Can anyone tell me if they have a workaround to do this or why my condition won't work?
Thanks
Do the below for each item in your checklist (If you want to see which items are not checked):
{{#if(issue."Checklist Custom Field".value.indexOf("Item in Checklist").max.eq(-1))}} Item in Checklist was NOT checked {{/}}
Hi @Nathan Gasseau,
Since your checkboxfield can have multiple values, then 'issue."My custom checkbox field".value' doesn't return a single value. It returns a list of values. See documentation of smart values lists here:
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/
https://confluence.atlassian.com/automation/examples-of-using-smart-values-with-lists-993924631.html
I tested your scenario out, with slightly different values, and found that you should be able to do this:
{{#if(issue."MyCustomCheckboxesField".value.first.indexOf("Checkbox3").eq(0))}}
Checkbox3 was checked
{{/}}
As you can see, I'm using "first". So if they picked it second, then this wouldn't pick it up. Unfortunately there is no "contains" function I'm aware of for SV lists, although you could work around it by using multiple checks with ".get(0)", ".get(1)", etc.
Value: {{issue."MyCustomCheckboxesField".value}}
IndexOf: {{issue."MyCustomCheckboxesField".value.indexOf("Checkbox3")}}
V1: {{#if(issue."MyCustomCheckboxesField".value.indexOf("Checkbox3").eq(-1))}} Checkbox3 was NOT checked {{/}}
V2: {{#if(issue."MyCustomCheckboxesField".value.first.indexOf("Checkbox3").eq(0))}} Checkbox3 was checked {{/}}
Log action
Value: Checkbox3, Checkbox4
Log action
IndexOf: 0, -1
Log action
V1:
Log action
V2: Checkbox3 was checked
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Stephen Wrathall Thanks for your answer it was very helpful.
This is ok if I have a small checklist with less than 3 options, but it gets complicated if the checkbox list has more options.
Are you aware if anyone is working on a .contain function of some sort because I feel like this is a pretty basic need when working with lists.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Welcome to the Community!
If I understand your usecase correctly, I think you could use our App Issue Checklist Free or Pro to create and operate the checklist and then use the {{fieldChange.fromString.match("(?m)(^\* \[] Checkbox 1$)")}} and {{fieldChange.toString.match("(?m)(^\* \[x] Checkbox 1$)")}} smart values/ function to search the Checklist Text custom field to see if the change to the field did affect the checklist item in question.
This is much easier to duplicate than the solution proposed by @Stephen Wrathall (great learning opportunity by the way, thanks!) but it requires the use of our third-party app.
For this to work you'd need to enable the Save Checklist data to Jira custom fields option in our app's global settings, so the Checklist Text field actually does get synced with the checklist in the UI.
If you need more guidance on how to make this work, feel free to ask here or reach out to our team via our service portal.
Cheers!
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.