Forums

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

Removing Values in One Variable That Exist in Another

Mafe Ortega May 20, 2025

Hoping someone can help me with a Smart Values question.

I have two variables defined in my automation rule:

var X: "e5a9e2ce-3d34-47b2-bc03-078197c2a7cf", "c1466970-6196-4741-9425-237c3466b37d", "dc1603c3-6941-4003-a660-1f522f8d4b5f", "ee49ea67-3549-4733-a3d3-98b24c35f852"
var Y: "c1466970-6196-4741-9425-237c3466b37d", "ee49ea67-3549-4733-a3d3-98b24c35f852"


What I want to do is remove any values from var X that also exist in var Y.
Expected result:

var Z: "e5a9e2ce-3d34-47b2-bc03-078197c2a7cf", "dc1603c3-6941-4003-a660-1f522f8d4b5f"


Is there a way to do this using Smart Values in Jira automation or any other way to do it?

1 answer

3 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.
May 20, 2025

Hi @Mafe Ortega 

There are a couple of ways to do this; let's try the one using a regular expression and the replaceAll() function.  First the answer and then how it works:

  • action: create variable
    • name: varX
    • value: what you show above
  • action: create variable
    • name: varY
    • value: what you show above
  • action: create variable, to build a regular expression to remove the varY values
    • name: varRegEx
    • value: 
({{varY.remove("\"").split(", ").join("|")}})
  • action: something that needs the values removed from varX
{{varX.remove("\"").split(", ").replaceAll(varRegEx, "").match("(.++)").asJsonString}}

 

How that works...

  • Your variables contain double-quotation marks, and those must be removed to work with the later steps. We use the remove() function to do this, escaping the double-quotation mark for the removal.
  • We need a regular expression to remove those values.  After we cleanup varY, we split() it into a list and join() it with pipe characters to make an expression such as: (A|B|C)
  • Chaining those earlier operations, we now use replaceAll() which takes the regular expression and replacing any values found with an empty string
  • The result of the replacement could leave empty spaces in the list, such as: E, , F, G.  And thus we add a match() function with a regular expression to only return non-empty results.
  • Now we have the answer, although without the double-quotes. We can add those back with the asJsonString function; this could also be done with iteration.
  • The result is a list of values. Please join or iterate them as needed for {{varZ}}

 

The other way do do this is with a regular expression to directly remove the values (using negative lookahead). I have observed inconsistencies using this with rules, so I recommend sticking with replaceAll() rather than trying to do this with a single match() expression.

 

Kind regards,
Bill

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.
May 30, 2025

Hi @Mafe Ortega 

Just following up to check if this answered your question.  If so, please consider marking this one as "answered".  That will help others with a similar need find solutions faster.  If not, please let the community know what help you need with the rule changes.

Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events