JIRA automation, and a working example of the Split function for smart values

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.
June 2, 2020

Greetings, community!

Who has a working example of using the Split function accessing the values in the result array?

I am able to split things, and I even figured out how to work around non-splitting characters.  (For example, replace periods with another character prior to split.)

But, when accessing the values, the results are consistently:

  • {{field.split("x")}}    Returns the array correctly.
  • {{field.split("x").first}}    Returns the first element of the array correctly.
  • {{field.split("x").second}}    Returns an empty value. Same for other numbers.
  • Dereferencing the array with [n] notation does not appear to work either.

 

Thanks for any help you can provide!

2 answers

2 accepted

6 votes
Answer accepted
Peter Reiser
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.
October 12, 2020

Example on how to extract the email domain of a reporter

{{reporter.emailAddress.split("@").get(1)}}

 

We use this in Jira Automation to exclude certain domains to be added to certain organisations

Mark de Bont [Terberg] October 26, 2020

Thanks, this is really usefull. Was looking for this ;-)

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.
October 26, 2020

Thanks, @Peter Reiser for that example.

mb January 30, 2024

Hi @Bill Sheboy @Peter Reiser I am also struggling with the regex split function. I am trying to use the split function on the "responders" custom field (I created a smart variable to make it more readable) in order to retrieve the user ID from the value. Unfortunately, my variables are always empty.

Do you have any idea what I am doing wrong?

Not even splitting by "user" gets me anything.

{{responders.split("user").get(1)}}

I suppose, I have to somehow point to the value of the responders field?

When I do a log action on "responders", I get:
Responders value is: {ari=ari:cloud:identity::user/<PROFILEID>, name=<PUBLICUSERNAME>, type=user, avatarUrl=https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/M-4.png}

But after using the split function, the new variable is always empty.

Here's the link to my problem that I am trying to solve.

mb January 30, 2024

The regex that I wanted to use initially was:

{{responders.split("user/").get(1).split(",").get(0)}}

 

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.
January 30, 2024

Hi, @mb 

To help focus the conversation, let's use your question / thread to help solve this.  Thanks!

https://community.atlassian.com/t5/Jira-Service-Management/Send-email-to-incident-responders/qaq-p/2592921

Kind regards,
Bill

Like mb likes this
5 votes
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.
June 12, 2020

Hi, community!

After a comment from an Atlassian developer on another question, it appears the problem is the documentation for text functions, not the split() function itself.  The gap may have been caused when the information was ported over after Atlassian acquired the automation product.  Who knows...

Split produces a list, and lists are not accessed as .first, .second, etc. as described in the doc.  Instead, they use function returns (note the parenthesis) and numerical, not literal indexing:

.first()

.last()

.get(n)  where n is the 0-based index for the array.

Please see here for more details on list access:

https://support.atlassian.com/jira-software-cloud/docs/smart-values-lists/

Nick Muldoon
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 16, 2020

Thanks @Bill Sheboy, you saved me a ton of stuffing around. Greatly appreciated!

Cheers,
Nick

Like Bill Sheboy likes this
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 17, 2020

Nick, I am glad that helped you. 

__Bill

Nikola Gaydarov July 1, 2022

Hi @Bill Sheboy , can you delete an item from the array? Say I am looking for cars, get(0) = BMW; get(1) =Audi and get(2)=Boing, so I want to delete the last one and if I make split().size to receive 2 instead of 3. Can this be done? Cheers, Nikola

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.
July 1, 2022

Hi @Nikola Gaydarov -- Welcome to the Atlassian Community!

I have not tried that, and...

You could probably use match() with a regular expression to expand the other values into a new list/string, and then reform the list, either directly or with join().

You could also try using smart value list filtering to create a new list be removing the non-matches.

Kind regards,
Bill

Sam Huawey May 22, 2024

@Bill Sheboy it is a little bit late but I have an issue with the split function.

lets suppose mytext is DB-223, DB-224, DB-225

I use code 

{{#mytext.split(", ")}}{{index}} - {{.}} {{/}}

According to documentation split returns an array of strings and the code above should return

0 - DB-223, 1 - DB-224, 2 - DB-225

But it returns 

0 - DB-223, DB-224, DB-225

Looks like it does not think that split produces a list.

What I am trying to achieve is to convert text DB-223, DB-224, DB-225 to

<jira_url/DB-223|DB-223>, <jira_url/DB-224|DB-224>, <jira_url/DB-225|DB-225>

Is there any way to do that using split function and list notation #?

Sam Huawey May 22, 2024

Answering to myself :)

I was able to achieve it by replaceAll 

{{mytext.replaceAll("(DB\-\d+)", "<jiraurl/$1|$1>")}}

Like Bill Sheboy likes this

Suggest an answer

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

Atlassian Community Events