Forums

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

Automation & tagging - there must be a smarter way for me to do this

Rory Gould March 23, 2022

Hi everyone, so whilst technically my automation is working it is bloated and likely far more complicated than it should be.

For talks sake, what I am trying to achieve is to have the summary of every new ticket searched for a countries name OR countries possessive name OR top level domain, this is for a list of around 40 countries, so around 120 strings. From there I want it to create a label that includes the country name.

Currently my automation workflow looks like:

Country 1

issue fields condition: Field(summary) Condition (Contains) Value (Germany)

Then: Edit issue fields: Labels(Germany)

issue fields condition: Field(summary) Condition (Contains) Value (Germany's)

Then: Edit issue fields: Labels(Germany)

issue fields condition: Field(summary) Condition (Contains) Value (.de)

Then: Edit issue fields: Labels(Germany)

Ideally I'd rather it ran like:

Country 1

- If: any match; Summary contains Germany OR Germany's OR .de

- Then: Edit issue fields: Labels(Germany)

 

 

 

2 answers

2 votes
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 23, 2022

Hi @Rory Gould 

From what you have described for your use case, you are trying to do this in an Automation for Jira rule.  Is that correct?

If so, this will not work with that many countries.  An automation rule can only have 60 components (trigger, actions, branches, conditions), and your rule would need at least:

  • 40 countries x (1 condition + 1 action) + 1 trigger = 81 components.

You do not show an example of your actual summary fields, and I wonder if instead you could do part of this use case with regular expression matching in a more generic manner...using less than 10 components. 

One challenging part is you want to translate the 2-character country code to the country names.  Another is that you could run up against other automation limits; perhaps there is a maximum length string for a regular expression in this tool.

I suggest pausing to reconsider this problem and determine if there is a way to get the country information into its own field when the issue is created.  You do not indicate the source of the issues so it is unclear if that is an option.

Kind regards,
Bill

Rory Gould March 24, 2022

Hi Bill, thanks for the reply. I'm not too hot with using the advanced/compare function/regular expression function and am not sure how I would complete it. Something like

{{issue.summary}}

contains

???

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 24, 2022

Again, I first recommend trying to get the data into a dedicated field to eliminate the need for parsing.

After a quick test, you may only partially be able to solve this as the regular expression parser for automation rules does not appear to implement word boundaries.  So you could find "Germany" and "HeresGermanyCountry".

I tested an expression like this with a very long 200+ country string I built, and it successfully found the string, which I put into a Created Variable for later use.  Here's an example with just four countries.  

{{issue.summary.match(".*(Germany|France|Italy|Spain).*")}}

The country name checks is probably going to be okay for your needs.  The 2-character country code is probably a non-starter due to the missing word boundary support: that will match on many strings potentially.

Like Rory Gould likes this
Rory Gould March 25, 2022

This is amazing @Bill Sheboy , thank you!!

Like Bill Sheboy likes this
1 vote
Rafael Costa
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 23, 2022

You are using the contains operator, so contains Germany and contains Germany's is ambiguous, once contains Germany match Germany and Germany's, right?

But put .de in the same condition idk how to do, idk where this automation is running (my groovy, workflow, scriptrunner...)

Rory Gould March 24, 2022

Hi Rafael, yes it is redundant. The automation is running in jira

Rafael Costa
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 24, 2022

Right. You can to do it with a simple post function script, like below:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

def labelManager = ComponentAccessor.getComponent(LabelManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
 
def matches = ['germany','.de']
def newLabel = ['Germany']

if (issue.summary.toLowerCase().contains(matches[0]) || issue.summary.toLowerCase().contains(matches[1])){
  def existingLabels = labelManager.getLabels(issue.id)*.label
  def labelsToSet = (existingLabels + newLabel).toSet()
  labelManager.setLabels(user, issue.id, labelsToSet, false, false)
}

set this script as Groovy inline script on your workflow step 

Like Rory Gould likes this
Rory Gould March 25, 2022

Thanks @Rafael Costa , I will try this

Like Rafael Costa likes this
Rafael Costa
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 25, 2022

Try then let me know if this works!

Suggest an answer

Log in or Sign up to answer