Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation: Trying to create labels based on a combination of fields.

George Tsemberlis March 8, 2023

Hi there! For the sake of this question we have three custom fields in play:

 

CustomField1 - a single select Radio Buttons field

CustomField2 - a Checkbox field

CustomField3 - another single select Radio Buttons field

We need to power a couple automations based on combinations of these fields, but CustomField2 has 12 options in it so the possible permutations would be a lot to hard code. What we want to do is iterate through the list of CustomField2 selections on an issue, and create labels combining the values of all 3 fields together.

Example:
Customer selects CustomField1 "Value A"
Customer selects CustomField2 "Value A", "Value D", "Value F", "Value M"

Customer selects CustomField3 "Value C"

 

Ideally this creates 4 labels:

CustomField1.A-CustomField2.A-CustomField3.C

CustomField1.A-CustomField2.D-CustomField3.C

CustomField1.A-CustomField2.F-CustomField3.C

CustomField1.A-CustomField2.M-CustomField3.C

in the issue

 

Is this possible? 

2 answers

1 accepted

1 vote
Answer accepted
Bill Sheboy
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.
March 9, 2023

Hi @George Tsemberlis 

I suggest not using branching to solve this.  Branches on more-than-one-thing (e.g. JQL, advanced branches, etc.) process asynchronously and in parallel.  If you are repeatedly trying to update the same issue you could run into collision and timing challenges.

Another way to solve this, and make one single issue edit, is to use an iterator over your multi-select field to build all of the labels in one JSON expression, and then use advanced edit to save them.

For example...

  • create a variable
    • variable name: varAddLabels
    • smart value...
{{#issue.customField2}}{ "add": "{{issue.customField1.value}}-{{value}}-{{issue.customField3.value}}" } {{^last}}, {{/}}{{/}}

This works by iterating over the values of your customField2, and adding the other field values around them, to build up a JSON expression.

  • and then edit the issue, using the More Options to add JSON for adding labels
{
"update": {
"labels": [
{{varAddLabels}}
]
}
}

 

Three more things...

I recommend adding a condition after your trigger to check if your fields have any values selected before proceeding to adding/changing labels.

What do you want to do if the custom field values change?  Rather than performing updates, you may need to first remove all existing labels and always write them anew.  If that cannot be done for some reason, I suspect this approach may not be viable for you.

And, automation is often about experimentation and learning.  It can help to look at the examples in the automation library to combine ideas from other rules to solve your needs.

 

Kind regards,
Bill

Kristopher Perez
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.
March 9, 2023

Great idea with using the iterative on the second custom field value! I’m still trying to get used to using this and seeing more examples like this really me dig deeper into Automation capabilities. Bravo!

George Tsemberlis March 10, 2023

This feel so close! It's definitely iterating an printing multiple labels but for whatever reason the {{varAddLabels}} variable is only getting populated with the value of the second field (eg the one that's just {{value}}). Am I missing something in the syntax here? Everything else is in the format of issue.customfield

 

Screenshot 2023-03-10 135402.png

 

The individual parts of the (eg customfields 1 and 3) have a valid value when checked in the audit log, just for whatever reason they're not showing up creating the AddLabels variable

Bill Sheboy
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.
March 10, 2023

Would you please post an image of your Create Variable action for varAddLabels?  This could be an iterator thing that needs some adjustments.

George Tsemberlis March 10, 2023

Added a codeblock since its a bit wide to screenshot

Custom Field 1 is a date

Custom Field 2 is the multi-select checkbox (parses correctly)

Custom Field 3 is a number

Rest are standard fields.

 

{{#issue.CustomField2}}{ "add": "{{issue.CustomField1.format("yy")}}{{issue.project.key}}{{CustomField2}}{{issue.CustomField3.round}}{{issue.summary.charAt(0).capitalize()}}" } {{^last}}, {{/}} {{/}}
Bill Sheboy
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.
March 10, 2023

Okay, my mistake...I forgot something I learned a while ago: once inside of an iterator, you cannot access things (e.g., smart values) from a higher scope.

And so once inside the iterator for your custom field, the issue fields are no longer visible.  The work-around is to build this expression in steps, by first iterating and then adding your other content.

  • create the variable, but put in placeholder text strings (e.g., DATEFIELD) for your fields like this

{{#issue.CustomField2}}{ "add": "DATEFIELD PROJECTKEY {{value}}NUMBERFIELD SUMMARYSTART " } {{^last}}, {{/}} {{/}}

  • then use replace to substitute in the final values...and the important part: convert the number field to text with format("#") or everything collapses to null.

{{varAddLabels.replace("DATEFIELD ", issue.CustomField1.format("yy")).replace("PROJECTKEY ", issue.project.key).replace("SUMMARYSTART ", issue.summary.charAt(0).capitalize()).replace("NUMBERFIELD ", issue.CustomField3.round.format("#"))}}

George Tsemberlis March 13, 2023

@Bill Sheboy perfect! Works just how we needed Thank you so much!

Like Bill Sheboy likes this
0 votes
Kristopher Perez
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.
March 8, 2023

What is the end goal of getting these concatenated labels created?  And why do you need each permutation as a separate label?  I'm just trying to understand the logic.

George Tsemberlis March 9, 2023

We functionally need to create a "UPC" or (however you want to think of a unique identifier) that contain information derived from several shared custom fields. The checkbox field contains the version that can differ between related products. The idea is to store these UPCs as labels because there may not be a strict 1:1 relationship between a product and a "run" of that product

Think of it like:

Car Model A, and having to create UPCS for Car Model A (Blue), Car Model A (Red), and Car Model A (Yellow) so we can create Issues for the production runs of the red, yellow, and blue cars.

Automation current looks something like this: 

"Order Versions" field is the colors of car basically
The {{NewOrder}} variable is the UPC based on the static fields, and the color

it quite nearly works, but the automation doesn't seem to be returning to the "top" of the loop and only creating the UPC for the "Blue" car if all 3 colors are selected.

Screenshot 2023-03-09 181740.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events