Forums

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

Remove an item from custom variable

Zaine Abaddin August 27, 2025

The goal:

Take all mentions from the last comment, filter out the issue's current assignee if they are added and insert the users mentioned into a custom field.

The approach:

split the mentions from the comment into a custom variable and use that to insert into custom field

The problem:

I'm struggling to filter out the current assignee from the array

I've tried:

I know i can use advanced branching but as this is part of a bigger autmation, this isn't an option.

I've tried looping through array and filtering out the assignee but it doesn't work.

I've tried using different functions like .replace .remove but no luck with any of these.

I don't even know at this point if I'm approaching this in the right direction as I don't really work with smart values.

Can someone guide me in the right direction?

This is what is being used to create the custom variable:

{{issue.comments.last.body.replaceAll("\\n", "").split(" ").substringBetween("[~accountid:", "]")}}

1 answer

0 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.
August 27, 2025

Hi @Zaine Abaddin 

For a question like this, context is important for the community to help.  Please post the following:

  • what version of Jira are you using: Cloud, Server, or Data Center
  • for Cloud, what type of project is this: company-managed, team-managed, JPD, etc.
  • an image of your complete automation rule in a single image for continuity
  • images of any relevant actions / conditions / branches
  • an image of the audit log details showing the rule execution
  • explain what is not working as expected and why you believe that to be the case

Until we see those...

 

From what you describe, there are at least a couple of ways to do this: 

  1. After extracting the accountId values from the comment mentions, using inline iteration and the replace() function, substitute the issue.assignee.accountId value with an empty string, and then clean up to remove any empty / left over spaces in the list with match("^(.++)")
  2. Again, extract and iterate the accountId values, and using inline iteration, use a dynamic regular expression to exclude the assignee's value.  That is similar to methods used in this article: https://community.atlassian.com/forums/Automation-articles/Automation-concepts-Find-Overlaps-Between-Lists/ba-p/3045704

I recommend using the first method as I have observed inconsistent results with automation rule support of regular expressions which do not contain a string.

 

Kind regards,
Bill

Zaine Abaddin August 28, 2025

Thanks for the response @Bill Sheboy 

This is on a company managed project but the automation will run across both company and team managed projects.

It is on the cloud version of JIRA.

 

Currently I have this which extracts the mentions and updates a custom field. the aim is now to insert all mentions excluding the assignee if they are included.

This is using a manual trigger for testing but is on a scheduled trigger when its live
Capture.PNG
I've tried iterating through it and printing out a comment so i can see if it works. This is what I've tried:

Split the mentions into a custom variable called mentionedUsers using:

{{issue.comments.last.body.replaceAll("\\n", "").split(" ").substringBetween("[~accountid:", "]")}}

Then print out a comment trying to loop over the variable and only print if is NOT the assignee using:

{{#mentionedUsers}}
{{#if(not(issue.assignee.accountId))}}
{{.}}
{{/}}
{{/}}

However, it just seems to be printing out everything including the assignee. I've printed out the custom variable and the assignee accountId to make sure they are the same and they seem to be so I'm a little stumped.

my understanding is that it should check if the current index is NOT the same as the assignee.accountId and the {{.}} should print out whatever is on the current index. Am I on the right track?

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 28, 2025

Thanks for that information, @Zaine Abaddin 

First, your variable is text, and needs to be split() back into a list for iteration

And...The symptom you are seeing is a long-standing limitation in the long-format of list iteration: Inside of a long-format iterator, only data from that scope, and lower is visible.  Thus, the assignee cannot be "seen" inside to filter the variable when iterated.

 

One possible workaround for this scenario is to use inline iteration, as that allows access to external data:

{{issue.comment.last.body.replace("\n", " ").split(" ").match("\[~accountid:(.*)\]").distinct.replace(issue.assignee.accountId, "").match("^(.++)")}}

How that works is:

  • for the last comment's body
  • replace any newlines with spaces to avoid confusing the later match()
  • split on spaces into a list, reducing the scope to check each item
  • match() to get the accountId values
  • add distinct to remove duplicates
  • replace any instances of the assignee's accountId value with an empty string
  • add a final match so only non-empty results are returned

 

Some of those steps could be combined using replaceAll() with the regular expression, although I have seen that function be "glitchy" sometimes.

Suggest an answer

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

Atlassian Community Events