Create an Array object in automation for Jira

Daniel Alonso
Contributor
September 19, 2022

Hi Community,

I need to compare two Select custom fields and provide an output with the distinct values, for example:

FieldA has the values for apps: A, B, C, D

FieldB has the values for apps: C,D, E, F

I need to compare both field selections and give as output the list without duplicates.

This is important because based on the selection, I need to create a sub-task and I want to avoid creating duplicates.

Any idea how can I do it with Automation for Jira?

Thank you.

3 answers

3 votes
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2022

@Daniel Alonso 

To my knowledge, unfortunately, this is not possible.

Values from field A will be a list.

Values from field B will be a list.

Creating a variable with these two lists, will yield an "array" of arrays, and you can't use the list.distinct smart value to get the unique values from these two field. A while ago I've tried that for another user, but couldn't succeed :( Feel free to try and if you can manage to do it, please update here!

You could do that if you had an app in which you could run groovy, or jira expressions and had built-in listeners (such as scriptrunner, or JMWE).

1 vote
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.
September 19, 2022

Hi @Daniel Alonso 

Yes, and...to Alex's answer: sadly there are not AND/OR operators for fields with which to do this.

If you have a limited number of selection options, you could do this with created variables, logical functions and if/else conditions...but that would be a brittle solution for maintenance.  The upper limit is due to the maximum number of components allowed in a rule.  For example...

  • trigger: some trigger for your source issue
  • action: create a variable depending upon the values of found in FieldA and FieldB
    • name: varAppA
    • smart value: {{#if(or(exists(issue.FieldA.name.split(",").match("(myAppAName)")),exists(issue.FieldB.name.split(",").match("(myAppAName)"))))}}myAppAName{{/}}
  • actions...to repeat for all of the applications values as variables
  • create the subtasks by either...
    • use if/else conditions to check the apps, or
    • concatenate all of the created variables together with commas between, and split them back apart using an advanced branch

You could also take a chance and build the first variable as one long string for all possible apps, although that sounds even more difficult to maintain.

Kind regards,
Bill

0 votes
Aaron P.
Contributor
May 25, 2023

If you use an IF block, you can query for each component using the "Contains any of" option and add a second condition with an OR for the second field.

In your case, you can check if the field FieldA has any of the values: C, D OR the field FieldB has some of the values: C, D

screenshot_547.png

Suggest an answer

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

Atlassian Community Events