Update checkbox field (select additional values) with automation
Asked by Rebecca:

Hi there,

I'd like to update a checkbox custom field via automation in a parent issue like this:

The Checkbox custom field in the parent contains 4 options:

* Approval A is set
* Approval B is set
* Approval C is set
* Approval denied

When Subtask A is resolved --\> then the Checkbox field in the parent should select the Value "Approval A is set"

When Subtask C is resolved --\> then the Checkobx field in the parent should select the value "Approval C is set" (++additionally++ to "Approval A is set")

... same goes for Subtask B.

With the standard in Automation I can only always replace the values that are already selected in the Checkbox.

But what I need: all Approvals A, B, C should be set before the parent issue can move on in the Workflow (so each subtask approval should add a value in the checkbox field).

This is why I tried to use JSON... and this is where I am completely lost. How can I update the field value so that any approval given is selected addionally to approvals that were already given?

I tried this via JSON for "Edit issue fields", but it is not working:

```
{
"update": {
"customfield_14809" : [{ "value" : "Approval B is set"}]
},
}
```

What did I do wrong?

Thanks!


Answers:
author: Darryl Lee
body: Hi [@Rebecca](/t5/user/viewprofilepage/user-id/4608278) - this was a fun one - it this took a bit of trial and error.

Since a multi-select field is kind of like **Link** or **Request participants** fields in that they can hold multiple objects, I followed those examples from [Advanced field editing using JSON](https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/) and came up with this, which seemed to work:

```
{
   "update": {
      "Multi Select": [{ "add": {"value": "Approval A is set"}}]
   }
}
```

(Where "Multi Select" is the name of my field. You don't have to use field ids, and for clarity in my rules, I prefer to use field names. This is only a problem if you later rename a field. I try to avoid that.)

comments: author: Jarrod Reimann
body: If I may pile onto this, as I am having the same issue but this solution did not work out for me. I think there may be more to my story though, because I am deep into this multi-branch automation (7 branches) and for some reason, a Field I have been setting using the standard "Choose field to set" --\> Select values is not offering up values that it earlier was.

Literally what I mean is in one automation rule, I have multiple **Edit Issue** components where I edit the field "Software" to set "Office 365" and "Adobe Acrobat". In at least two of my **Edit Issue**components, these values are not even an option from the list. I don't really understand why that would be, especially within the same rule.

I think this is important for the problem I am having. Ultimately, I need to be able to "add" these values where values already exist (without affecting the existing ones) and I believe I'll need to use the **Additional Fields**section and a JSON to do so, but, that isn't working either, and I suspect it is related to the same thing causing my values not to appear in the list. I hope this makes sense.


author: Darryl Lee
body: Ah, more branches, more problems.

The question I'd have is whether your branches can potentially touch different Projects, **and** where you have different contexts set up for the "Software" field, based on Project.

Otherwise, yeah, that's weird why some options would not be available in Automation.

If you could take some screenshots of your rule (I realize with big rules this is hard), we might be able to find something obvious.

And yes, if you want to add values without affecting existing ones, you **will** need to use Additional Fields + JSON.

If you already tried that, there might be something in the Audit logs that would give us a clue, so if you see any error messages, those would be good to share here as well.


author: Jarrod Reimann
body: The rule runs left to right (with each branch in its own column here). This is really just for organization and control while I test out all the granular pieces. Eventually I expect I will build a single if/else as opposed to having all these branches. I didn't think this could cause issues though.

**Using the above-mentioned JSON example, I did get an error:**

Error editing issues

EMP-51 (Field 'customfield_10071' cannot appear in both 'fields' and 'update')

**My JSON object was:**   
{  
"update": {  
"Software": \[{ "add": {"value": "Adobe Acrobat"}}\]  
}  
}


author: Jarrod Reimann
body: I am going back to the drawing board on this. My Custom Field, currently being used on tickets, does not appear at all in Settings \> Issues \> Custom Fields. I cannot explain it. I am going to start over.


author: Darryl Lee
body: Hi [@Jarrod Reimann](/t5/user/viewprofilepage/user-id/4192037)

Re: your error, that's telling you that you can't have the Field dropdown selector showing _and_ try to update it with JSON. If you just remove the dropdown selector (by unchecking it from the list of fields to set), that will get rid of that error.

But I have a few other questions:

1. Is this rule scoped to a single project, like so:

![Screen Shot 2023-02-17 at 10.53.35 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/241020iC865974A80FFF0E4/image-size/large?v=v2&px=999 "Screen Shot 2023-02-17 at 10.53.35 AM.png")

2. In the bottom-left corner that Project, does it say if this is a company-managed project, or team-managed?

![Screen Shot 2023-02-17 at 10.53.57 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/241021iA3793A493E246407/image-size/large?v=v2&px=999 "Screen Shot 2023-02-17 at 10.53.57 AM.png")

Team-managed custom fields will not show up in the global Custom Fields interface.   

It seems like custom fields for Team-managed projects are ... inconsistently supported in Automation:

* [Automation for custom fields in team-managed projects](https://community.atlassian.com/t5/Jira-questions/Automation-for-custom-fields-in-team-managed-projects/qaq-p/2057663)


author: Jarrod Reimann
body: You are correct - it is team-managed and I sort of ended up figuring this out myself reading around. So what I've done is removed all my fields from the project and re-created the custom fields from the Custom Fields screen to ensure they are globally accessible.

Also discovered the solution you pointed out in #1, silly mistake on my part.

My rules are running now and values are adding without overwriting.

Thanks for your help, I'm in good shape now.


author: Darryl Lee
body: Awesome! Glad to hear you got it worked out. Yeah, looking at the JSON, that looked just fine.


author: Rebecca
body: Hi Darryl,

I'm glad you enjoyed the challenge! :) Thanks so much for you help!

I just implemented and tested it in our Software projectr and it works exactly as we needed it to.

Best regards  
Rebecca

comments: author: Darryl Lee
body: Awesome to hear that it worked! I wonder if you might be willing to share a screenshot of the final rule because I was curious about how you would be identifying each subtask to check if it was closed.

Do you have a corresponding rule that automatically creates subtasks A-D and names then accordingly in their Summary?

So then do you trigger for when any Subtask is closed and then do four "ifs" to check if it is A-D and then tick the appropriate checkbox?

Because I bet I could get that down to one checkbox by using the **match** function. :-}


author: Rebecca
body: Hi Darryl,

this is what the final rule looks like:

![Automation.png](https://community.atlassian.com/t5/image/serverpage/image-id/235773i871BCA255BD448D5/image-size/large?v=v2&px=999 "Automation.png")

...and so on.

And Yes, I do have a corresponding rule that automatically creates and names subtasks A-C while editing of the subtasks is not possible. Depending on the status the Subtask is transitioned to (approved/denied), the corresponding approval in the parent is set.

I never heard of the match function, how does it work? :-)


author: Darryl Lee
body: Actually, you might not need the match function at all.

So this assumes that the Summary of your Subtasks is exactly the same text of what the checkbox option.

So for example, one of your checkbox options is:

"Rezeptpr?fung und Gegenzeichnung (Produktentwickler) ist freigegeben" (thank you Google Translate?)

Then you could probably do something like this:

\* IF subtask is Approved

\* Then Edit issue fields Advanced

```
{
  "update": {
    "Checkboxes": [{ "add": {"value": "{{issue.summary.concat(" ist freigegeben")}}" }}]
  }
}
```

You'd only need the [text functions](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--) like **match()** function or **replaceAll()** if your checkbox options only contain part of the Summary. Like lets say your checkbox was only included who approved a subtask. So: "produktentwickler genehmigt". Then you'd use this for the value:

```
"{{triggerIssue.summary.match(".*\((.*)\)").concat(" genehmigt")}}"
```

You might use replaceAll() if your checkboxes didn't contain the approver, so you could remove it like so:

```
"{{triggerIssue.summary.replaceAll(" \((.*)\)","").concat(" ist freigegeben")}}"
```

The advantage here is that you would only need ONE IF block.

I tested that first example above and here's what it looked like:

![Screen Shot 2023-01-23 at 12.56.28 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/235796iC230D99F80FAE72A/image-size/large?v=v2&px=999 "Screen Shot 2023-01-23 at 12.56.28 AM.png")


Tags: checkbox

data-center

json