Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Adding a text string to an Epic Name depending on component's text

Daniel Schoeneck August 18, 2023

Hello all,

 

I have set up the following 2 automation rules:

  1. If in the field Component/s the component name starts with E add #EMP to the Epic name
  2. If in the field Component/s the component name starts with F add #FRA to the Epic name.


This works well as long as there is only ONE component selected in the Epic. But if there are 2 components selected, one starting with "E" and one with "F", only #EMP is added to the iEPic name...but I want #EMP and #FRA to be added to the Epic name.


Rule #FRA2.PNGRule #EMP2.PNGRule #EMP1.PNGRule #FRA1.PNGProblem_only #EMP.PNG
Any idea how to solve this?

4 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.
August 18, 2023

Hi @Daniel Schoeneck  and the community helping on this one!

You do not state the format of your epic name, so let's assume it is something like this:

EPICNAME [0 to many component indicators, prefixed by " #"]

Have you considered doing this in one step / edit action (without any conditions), using smart value list filtering? https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588

{{issue.epic name.substringBefore(" #")}}{{#issue.components}}{{#if(equals(name.left(1).toUpperCase(),"E"))}} #EMP{{/}}{{/}}

Please repeat the inner section for any component you want to handle

Also, you would need rules to make the update for different triggering events: issue create, components changed, epic name edited by other than rule, etc.

Kind regards,
Bill

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.
August 18, 2023

Ha - I should've known that Mr Sheboy would come in with a more elegant approach!  🙂

Daniel Schoeneck August 18, 2023

Thanky you @Bill Sheboy 
Never thought about that...or let's say: I did not know that this is possible I don't even understand how this code works  and how to implement into my automation rule ;)

What would be the advantage of your solution?


Wouter van den Berg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2023

Way cleaner solution definitely. The advantage here is a cleaner solution, less load for automation and no conditions that need matching before execution. 

The disadvantage was made clear the moment you replied. This is definitely more advanced. Upon you leaving the system, the one replacing you will probably have some questions how the logic works.

Thanks for sharing this clean solution @Bill Sheboy

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.
August 18, 2023

Yes, that is a more complicated approach. And...

In my experience, using automation rules requires learning, experimentation, and documentation.  Unfortunately that last one is tricky given current capabilities of rules.  A work-around is to document rules outside of the project, such as in Confluence.  I also save my rules in a test project, and write an explanation in the details so I can remember what I did last week  ;^)  I also add writes to the audit log to explain and assess progress in the rule processing.

 

Back to Daniel's questions about the suggestion I made...

The first part grabs whatever text in the Epic Name is left of the first Component indicator.  This helps when later updates of the Components field need to refresh the name.  https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#substringBefore-String-separator-

The next part is using the idea of list iterators, {{#someList}}{{someField}}{{/}} to allow walking over the Component values.  This technique is helpful to format things, list a list of issues for an email, or to build up a JSON expression.  https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#Combined-function-examples

And inside that iterator, we are using the newer feature of smart value, list filtering.  This helps to prune the list only to the values you want.  In your case, you wanted to check for specific components' prefix letters.

Finally how to use this: remove all of the condition tests, and a single expression could be used to update the Epic Name field in the Edit Issue action.

Like # people like this
Daniel Schoeneck August 18, 2023

@Bill Sheboy Very nice solution, I want to use it (unless I still don't fully understand it, but that is due to my lack of basic programming knowledge).

I have already created 3 rules that work pretty well using your code:

  • Add Squad #hashtag to Epic Name when Epic is created
  • Add Squad #hashtag to Epic Name when Component is added later
  • Remove Squad #hashtag from Epic Name when Component is removed

 

But one problem is left:

When there is already a component starting with "F" and I add a second component that start with "F", the hashtag #FRA is added once more. I only need the hashtag once in the Epic Name.

How to prevent it is added once more?Redundant hashtag.PNG

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.
August 18, 2023

First thing, smart value expressions can be built up from simple pieces.  And something what seems like a complicate mess can be explained.  That was a disclaimer for what follows...

Your revised goal is to find the distinct first letters of the component names, and use them to select your tokens/indicators to add to the epic name.  Fortunately smart value lists have a function to return just the distinct values: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#list.distinct

The challenge is how to get the distinct values and use that in a list filter?  Let's look at this step by step:

  1. Let's get just the first characters of the component names as a list with {{issue.components.name.left(1).toUpperCase()}} 
  2. We refine that by adding distinct to the end {{issue.components.name.left(1).toUpperCase().distinct}}
  3. And because that is a list, it can still be filtered, like this {{#issue.components.name.left(1).toUpperCase().distinct}}{{#if(equals("E"))}} # EMP{{/}}{{/}}

The tricky part is after we got to step #2, these are now just letters in a list, and no longer have anything to do with components.  And so we cannot filter on the "name" attribute any longer. 

Fortunately the iterator and conditional filter logic design is smart enough to compare the list element to the "E".

So your revised template would be this...as now this can happen together:

{{issue.epic name.substringBefore(" #")}}{{#issue.components.name.left(1).toUpperCase().distinct}}{{#if(equals("E"))}} #EMP{{/}}{{#if(equals("F"))}} #FRA{{/}}{{/}}

Like Wouter van den Berg likes this
Daniel Schoeneck August 18, 2023

Alright, so I need it actually for 3 different types of components

- Starting with E
- Starting with F
- Starting with S

So I tried this code:

{{issue.epic name.substringBefore(" #")}}       {{#issue.components.name.left(1).toUpperCase().distinct}}
   {{#if(equals("E"))}} #EMP{{/}}
   {{#if(equals("F"))}} #FRA{{/}}
   {{#if(equals("S"))}} #STE{{/}}
 {{/}}

But now it just removes all the hashtags from the Epic name. What might be wrong?


With this code it works nicely (except the problem that a hashtag might be added multiple times):
{{issue.epic name.substringBefore(" #")}}
{{#issue.components}}
{{#if(equals(name.left(1).toUpperCase(),"E"))}} #EMP{{/}}                {{#if(equals(name.left(1).toUpperCase(),"F"))}} #FRA{{/}}{{#if(equals(name.left(1).toUpperCase(),"S"))}} #STE{{/}}
{{/}Problem.PNG

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.
August 18, 2023

Fascinating...It is not removing them but they are off the field view on the page!  I believe if you click on the field and select all, you will find them off to the right side.

There is something happening due to the use of the stringBefore() function, the iterator, and the extra carriage returns/line feeds you have in the expression.  Please try pasting in this exact one and observe what happens:

{{issue.epic name.substringBefore(" #").trim}}{{#issue.components.name.left(1).toUpperCase().distinct}}{{#if(equals("E"))}} #EMP{{/}}{{#if(equals("F"))}} #FRA{{/}}{{#if(equals("S"))}} #STE{{/}}{{/}}

Please note I added a trim call and removed all extra CR/LF from the expression.

Daniel Schoeneck August 18, 2023

I tried it, but still the same behavior...
And I also did not find them in the edit mode of the field:

Epic Name.png

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.
August 19, 2023

I tried this with Jira Cloud, so I wonder if there is a difference as you are using Jira Server, correct?

Let's try writing this to the audit log to see if you see the expected values:

{{#issue.components.name.left(1).toUpperCase().distinct}}{{.}}{{/}}

The result should be the list of just the expected first characters, with comma separators, as a list (not as an array).  If it is an array we can try another work-around with join and split.

0 votes
Wouter van den Berg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2023

I can see your predicament. When there is a lot of changes you don't want to go back in and change the rules each time. Maybe you could extend the solution provided above with a regular expression. I don't remember if Server supports this but I assume it does. Use the branching logic that @Mark Segall provided but instead of component in you could use: 

^[eE] for matching components starting with e or E
^[fF] for matching components starting with f or FScreenshot 2023-08-18 at 16.15.12.png

0 votes
Wouter van den Berg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2023

Hi @Daniel Schoeneck

UPDATE: Sorry, didn't see you are on server. I'll leave the answer for the people that end up here using Cloud. 

I have tried a different approach. See screenshot: 

Screenshot 2023-08-18 at 15.24.27.png

Refetch in the first step might not be needed but I always do it anyways. In my case I did the comment action to see if it works but have a go at this. 

Goodluck. 

0 votes
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.
August 18, 2023

Hi @Daniel Schoeneck 

From your screenshots, it appears you're using Jira Server automation, correct?  If so this will be a little more tricky as you don't get the benefit of advanced branching. However, this could be possible and with a single rule.

Can you confirm whether the Epics will ever have more than 2 components?

Wouter van den Berg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2023

Ah didn't even notice that. Your approach would be {{issue.components.first.name}} and {{issue.components.last.name}} I presume? 

Like Mark Segall likes this
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.
August 18, 2023

I was actually thinking more along the lines of 

{{issue.components.name.get(0)}} and {{issue.components.name.get(1)}} but your approach will work too.  🙂

Like Wouter van den Berg likes this
Daniel Schoeneck August 18, 2023

Hi, 

yes the Epics can have an unlimited number of components

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.
August 18, 2023

Unfortunately, this makes things more complicated because we're constrained on being able to iterate through the components and components do not work with a wildcard search. 

Are your components constantly changing?  If not, you could go through a one-time pain point of creating two JQL branches:

  • BRANCH (JQL)
    For E*
    • Key = {{issue.key}} AND Component IN (E1, E2, E3, E4)
  • BRANCH (JQL)
    For F*
    • Key = {{issue.key}} AND Component IN (F1, F2, F3, F4)

If the components list changes more frequently, we may be running into limitations of what's possible with Jira Server automation.

Like Wouter van den Berg likes this
Daniel Schoeneck August 18, 2023

Component names might change frequently yes...
Would it help if we assume that there is a maximum number of components e.g. maximum of 4 components? (in reality 99,9999% of the components will have max. 3 components)

Daniel Schoeneck August 18, 2023

OH, and yes: there will be more Components be added frequently (E5, E6, ... and F5, F6, ...)

Daniel Schoeneck August 18, 2023

May be I need a completely different approach?

My ultimate goal is to have "hashtags" on the epics in the epic panel in the Scrum backlog (depending on the selected components in the epics), which allows to use the epic panel filter (which only can filter by the epic name...) 

 

Epic Panel in Backlog.PNG

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.
August 18, 2023

I think I found an answer to how to handle this:

  • IF CONDITION:
    • {{issue.components.name}}
      Contains Regex
      \bE\w+
  • ELSE CONDITION:
    • {{issue.components.name}}
      Contains Regex
      \bF\w+

I ran through a few tests in my environment and it seems to be working.

Wouter van den Berg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2023

Assuming each components starts with a capital. If you want to cover all options you can use: 

^[eE] for matching components starting with e or E
^[fF] for matching components starting with f or F

Daniel Schoeneck August 18, 2023

Thank you, I tried like this:

But it still only added #FRA to the Epic name although there is an Component starting with E:

 

Only FRA.PNGRule.PNGError.PNG

Wouter van den Berg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2023

You need to Branch. With If/Else automation will stop once it reaches a succes. 

Like # people like this
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.
August 18, 2023

Good call @Wouter van den Berg 

Like Wouter van den Berg likes this
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.
August 18, 2023

I would branch into current issue twice and in between the two branches, do a re-fetch

Like Daniel Schoeneck likes this
Wouter van den Berg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2023

Together we will solve this one @Mark Segall ;) 

@Daniel Schoeneck I saw you are using the Regex Mark has provided. Please make sure you have governance on Component creation. If a user adds a component without capital your rule won't pick this one up as match. The chances users will add a component without capital along the way is very likely if you'd ask me. I have added my solution for this but you are free to use Mark his solution but I still wanted to mention this again. 

Like Daniel Schoeneck likes this
Daniel Schoeneck August 18, 2023

Guys you are genius!

Now I have to make sure that the hashtags will be updated when a component is deleted or added later to the epic. 
I will try myself first ;)

Solved.PNGSolution1.PNG

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events