Condition to see if a specific checkbox option was checked or not using smart-values

Nathan Gasseau April 20, 2023

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

2 answers

0 votes
Christian Matthews
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 27, 2024

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 {{/}}

0 votes
Stephen Wrathall
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 27, 2023

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.

Working

Four Log actions

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 {{/}}

Four outputs

Log action
Value: Checkbox3, Checkbox4

Log action
IndexOf: 0, -1

Log action
V1:

Log action
V2: Checkbox3 was checked
Nathan Gasseau May 2, 2023

@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.

Wojciech Wardaszko _HeroCoders_
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.
May 3, 2023

Hi @Nathan Gasseau

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!

Suggest an answer

Log in or Sign up to answer