Missed Team ’24? Catch up on announcements here.

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

A4J Cloud - Advanced field editing match()

Neil Taylor November 23, 2022

Hello,

I am trying to get the match() statement to work in Advanced Field editing in a Jira Cloud Automation.

You can see what I have below - the first if I have as a match and it is not working.  The second if is an equals and it works without any issue.  Any ideas for what might need changed to get the match to work?  I've tried quite a few variations to get the regex working as expected, but I must be missing something.

(In Edit Issue action - advanced editing)

 

{ "update": { "customfield_16000": [ { "set": {"value": "{{#if(issue.summary.toLowerCase.match(\".*(crash).*\"))}}Crash{{/}}{{#if(equals(issue.summary.toLowerCase(), \"hang\"))}}Hang{{/}}"} } ] } }

 

There are no useful errors - essentially if i set my summary to "crash", it doesn't match either if in the statement so that is the only error going on that I can see in the audit logs.

Here's the match documentation I was going off of: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--

TIA!

4 answers

1 accepted

0 votes
Answer accepted
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2022

Got it! I named my custom field Cause (you don't have to use customfield_xxx, which makes rules easier to read).

This worked for me:

{ "update":
      { "Cause": [ { "set": {"value": 

     {{#if(issue.summary.toLowerCase.match(".*(crash).*").isNotEmpty)}}"Crash"{{/}} 
     {{#if(issue.summary.toLowerCase.match(".*(hang).*").isNotEmpty)}}"Hang"{{/}}
     {{#if(issue.summary.toLowerCase.match(".*(foo).*").isNotEmpty)}}"Foo"{{/}}
     {{#if(issue.summary.toLowerCase.match(".*(bar).*").isNotEmpty)}}"Bar"{{/}}
   } } ] }
}

Please keep in mind though that regexes are notoriously fickle things. You'll want to make SURE that you don't have causes that contain the same words.

Silly example: Was it a crash, or a rash, or ash that caused the problem?

Another problem. If the summary mentions more than one keyword, it will change your custom field to the last option you check. Example: "This crash was so bad. It made the computer Hang multiple times. Foo. Bar."

But I guess if your users are aware of the limitations of this approach, it should work. Neat idea, and fun to work out. Thanks for thinking of it.

P.S. OH, one thing I thought of is the possibility that somebody doesn't use one of your 60 (!) possible causes, or forgets.

Since Automation doesn't have an ELSE operator, you can't set up a final rule to choose "Other" or something like that. Instead I think the rule will end up erroring out. 

OH, I just read more in Jira smart values - conditional logic, and thought i could do it with an AND statement that contained with all the possibilities words coming up empty, but I'm not having much luck with that... Still hacking on it a bit.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2022

Ok, didn't need the AND, since I can do regex alternation using the pipe (|) character. But I did need the NOT operator because Automation's isEmpty function does not work very well, it seems.

So I added this ugly line after the other IF statements:

{{#if(not(issue.summary.toLowerCase.match(".*(crash|hang|foo|bar).*").isNotEmpty))}}"Other"{{/}}
}

I do advise you to type your rules out in a text editor (I'm a fan of vim), so you can check your parentheses, etc. and even format rules with proper indentation, etc. Makes it a lot easier to troubleshoot and find typos, etc.

For completeness, here's the reference for text functions like isEmpty, match, and isNotEmpty:  

Jira smart values - text fields 

Like Neil Taylor likes this
Neil Taylor November 25, 2022

Thank you @Darryl Lee !  I tested initially and that fixed the issue I was running into!  You bring up some good points as well that I will look into

1 vote
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2022

Oh wow. After figuring out the fix for "Other", I realized and tested to confirm that this could be done without any IF statements at all, IF you are willing to have your custom field options be all lowercase:

{ "update":
   { "Cause": [ { "set": {"value":
"{{issue.summary.toLowerCase.match(".*(crash|hang|foo|bar).*")}}{{#if(not(issue.summary.toLowerCase.match(".*(crash|hang|foo|bar).*").isNotEmpty))}}other{{/}}"
   } } ] } }

Note that the line with the matching logic must all be on one line with no spaces, because we are doing what you originally intended, "filling in" what goes between the quote marks for value.

For testing, I set the rule up to trigger on Summary change, and when I updated it, the Cause field updates after a second or so:

Screen Shot 2022-11-25 at 12.36.52 AM.pngScreen Shot 2022-11-25 at 12.38.00 AM.pngScreen Shot 2022-11-25 at 12.37.22 AM.png

Fun stuff!

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2022

So yeah, for this, you'd just need to generate a pipe-delimited list of your options, and paste it in twice. (Still need an IF/NOT to check for "other".)

The match operator is kind of handy since it returns what it finds.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2022

Oh duh, I guess if you really wanted the options to be capitalized, you could convert them BACK with the handy capitalize function.

{ "update":
   { "Cause": [ { "set": {"value":
"{{issue.summary.toLowerCase.match(".*(crash|hang|foo|bar).*").capitalize}}{{#if(not(issue.summary.toLowerCase.match(".*(crash|hang|foo|bar).*").isNotEmpty))}}Other{{/}}"
   } } ] } }

Like Jesse Wisener likes this
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2022

Annnnd, just before going to bed last night I had another idea since Atlassian lets you set default values for Smart Values. Could that be used for the "Other" value? Why yes, yes it can.

So then:

{ "update": 
  { "Cause":
     [ { "set":
{"value":
"{{issue.summary.toLowerCase.match(".*(crash|hang|foo|bar).*").capitalize|"Other"}}"
}
} ]
}
}

Whew. Ok, I think that's about as good as it gets. :-}

Like # people like this
Jesse Wisener
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 29, 2022

That is a work of art.

Like Stefan Salzl likes this
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 29, 2022

Awww, thanks @Jesse Wisener - and hi!

Like Stefan Salzl likes this
0 votes
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 23, 2022

Hi @Neil Taylor 

the # in using smart values is eigher used for iterating over a number of results or for calculation.

In case it‘s an if that checks 1 result this is not needed.

see conditions for smart values here:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/

Try to leave out the ‚#‘ as well as the closing ‚{{/}}‘

 

And furthermore:

Which type is the field of you‘d like to edit?

 

Best
Stefan

Neil Taylor November 23, 2022

Hi Stefan,

Thanks for the input!  I tried leaving out the #'s and the closing {{/}}.  By removing them, neither IF works as expected.  With those added, my equals works (e.g. if my summary is "hang", it sets my target field to "hang") and it's just the "match" not working.

The field type I am setting in this scenario is a single select field which has the values Crash and Hang.

Basically, my end goal here is to make it so a summary could come in with "My website crashed" and it would set the field to crash.  I'm really close as if i use equals and have the summary be exact hang, it sets the field, so i just need to extend this so it's able to do a match if it contains my term I'm looking for.  I could definitely do this in other ways, but since I will have over 50 terms, thought getting all of it into one action would be cleanest.

Thanks for the assistance and I'm all ears if you have any other ideas.

Neil

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2022

Hi @Neil Taylor 

thanks for your detailed description.

Tbh. I‘m not very familiar with regex so I just did a quick „crash research“ as I‘m having a hard time following your search pattern. 

Could you explain why it is

\".*(crash).*\"

 

Wouldn‘t that take the () around the string „crash“ into your search?

 

Best
Stefan

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2022

Hey guys, just a few notes:

@Stefan Salzl - the hashmark (#) is not just for iterating over lists. It's also used for the conditional if statement, and the {{/}} is how you close the if block.

You linked to this already (sorry), but Jira smart values - conditional logic describes this, and it in fact works outside of lists.

Re: quotes: Often with regular expressions you need to "escape" your quote marks with backslashes if you're trying to include quote marks "within" another set of quote marks. In this case @Neil Taylor was trying to return the value for his custom field in quotes.

Because the JSON is supposed to look like:

"value" = "Crash"

He was trying to do something like this:

"value" = "{{all-the-logic-to-lookup-and-return-value}}"

This might have worked, but seemed too complicated to me, so I put the quote marks within separate IF blocks and just repeat it, like so:

{{logic-to-check-if-summary-contains-crash}}"Crash"{{/}}
{{logic-to-check-if-summary-contains-hang}}"Hang"{{/}}

 

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 28, 2022

Hi @Darryl Lee 

Oh sorry for the confusion and thanks for clarifying this here. Always happy to learn things in more details :)

 

Best
Stefan

0 votes
Curt Holley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 23, 2022

Hi @Neil Taylor 
Welcome to the community!

I'm not sure exactly what you are trying to achieve, but are you aware of / could you make use of.....the Issues fields condition options around the summary field??
There are a bunch of options, not just "contains", and you can make use of smart values in the Value section, plus a case match option.

Worth a try? or have you already??
2022-11-24 10_53_55-Automation.png

Neil Taylor November 23, 2022

Hi Curt, thanks for the reply.  I could definitely do this, but ultimately I will end up with around 60 if's in my statement - I should have mentioned that - so what you suggest is very possible, it would just be a lot of conditions and actions.  I was hoping to use what I started above, to accomplish all my conditions and actions in one single action instead.

Like Curt Holley likes this
Curt Holley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 23, 2022

Right! that makes sense. Good Luck! as I have no other suggestions....sorry!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events