Automation distinct and formatted

Mark Segall
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 2, 2022

Hey there community,

I'm trying to set up a rule that is getting quite complex and hoping someone here can help me out.  Here's what I have so far in the rule:

  • I have a look up issues action that pulls in all blocked issues
  • I have a variable (varMyVariable) that gives me the Insight object attribute off of each of the blocked issues which is always numeric.  The variable looks like this:
    • {{lookupIssues.customfield_xxxxx."My ID"}}  
  • The results look something like this:
    • [123], [234], [345], [234], [789], [321], [1], [1], [10], [45], [654], [555],[54], [222], [777]

So far so good... Now I have some formatting requirements that seem to be eluding me.  The final result should look like this:

[123|234|345|789|321|1|10|45|654|555
54|222|777]

There are three requirements coming into play:

  1. Result should be pipe delimited - I've successfully accomplished this with a new variable:
    1. {{varMyVariable.replace("], [","|")}}
  2. Result needs to be distinct - I've failed every way I've tried this.  I've tried the following:
    1. {{varMyVariable.distinct}}
    2. {{lookupIssues.customfield_xxxxx."My ID".distinct}}
  3. Result needs to split to a new line after every 10 matches

Appreciate any insights for this.  

1 answer

1 accepted

1 vote
Answer accepted
Garrett McCreery
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 2, 2022

Hi Mark,

The distinct part...

The first attempt 

  1. {{varMyVariable.distinct}}

    This is not working because once you create a smart value-variable in Jira automation it turns it into a string, so it's not an array anymore, there for distinct will not work.

  2. {{lookupIssues.customfield_xxxxx."My ID".distinct}}

    What value did you get when this was run? This seems to be the correct syntax.

Mark Segall
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 3, 2022

Thank you for the quick response @Garrett McCreery 

It still returns all values.  Here are the results of my sample issue where I'm still using distinct against the lookupIssues result (I've highlighted the dupes in bold):

[4068], [11909], [3594], [4517], [4248], [13452], [1908], [3883], [1], [1], [1], [1], [10], [10000], [10123], [10321], [10432], [10543], [10654], [10765], [10876], [10123], [10123], [10789], [10], [1], [1], [1]

Spent a couple hours on this one yesterday and just can't seem to get this one to play nice.

Garrett McCreery
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, 2022

@Mark Segall 

ok, I figured out how you can do this...

Take your result variable, and split it by commas with the distinct function...

insightObjectIDs.split(",").distinct

screenshot.png

Then you can use the replace method to get it back to the pipe separator.

Garrett McCreery
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, 2022

The split function turns it into an array (or "list") where the distinct function can be run!

Mark Segall
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 3, 2022

Perfect!  That solves two of the three requirements.  Any chance you have any pearls of wisdom for creating a new line after each 10th result?

4068|11909|3594|4517|4248|13452|1908|3883|1|10
10000|10123|10321|10432|10543|10654|10765|10876|10789

Thank you again.

Garrett McCreery
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, 2022

I think the new line will depend on what application you are writing it out to. Where are you writing it to, a Jira field?

Mark Segall
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 3, 2022

Yes - This goes to a Jira field

Garrett McCreery
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, 2022

Since Jira Automation does not have a real action/branch that can do looping, you would have to create a separate automation rule that can loop itself until you reach the end of the divisible by 10. It's more than I can show on the community chat. But I hope that helps.

I use the incoming web hook automation rule whereas I pass in the initial list, use substring, split, etc to get to the first 10, save that in a different array looking variable, remove the first 10, and call the incoming webhook (itself) with the original (minus the first 10) and the new variable. I will check to see if there are 10 items left before calling itself.

When there are less than 10 left is when I would write it out to a field.

Does that make sense?

Mark Segall
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 3, 2022

This does make total sense and I was thinking that I may have to go the route of an additional rule to edit the field after the fact.  Thank you for all of your help on this.  I'm marking this as answered. 

Garrett McCreery
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, 2022

You are welcome and thank you!

Like Mark Segall likes this
Daniel Landino June 3, 2022

Hello @Garrett McCreery ! I have what I believe is a similar type of a problem you helped solve for Mark with not being able to use the distinct to remove duplicates.

I have tried to figure out what you did here but have been unsuccessful thus far

Do you mind taking a look at my use case?

I've tried so many different things and am stumped

Josh Marsh September 21, 2023

This is a great suggestion but it isn't working for me :( anyone know what I'm doing wrong?

customfield_12737 is a multi-select Assets field.image.pngimage.pngimage.png

Suggest an answer

Log in or Sign up to answer