Convert Array to List in smart values

Vishal Thakkur March 27, 2024

Hey community,

I'm trying to set up a rule that is getting bit complex and hoping someone here can help me out.  Here's what I have so far in the rule:


  • I trying to extract the IP address from the Jira ticket description, Now to extract that I am using regex in smartvalue - {{issue.description.match(".*(\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b).*").split(",").distinct}} 
  • Now when I am using split function then it's converting my List to array and displaying result like this - [10.12.80.8], [10.12.112.4] 
  • I don't want array [ ] as output because I need to send this data to webrequest which will not accept [ ].

  • So how do I remove the array [ ] and convert to list again?

2 answers

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.
March 27, 2024

Hi @Vishal Thakkur -- Welcome to the Atlassian Community!

For scenarios like this, context is important.  What would an example Description that contains your values look like?  Knowing that may help to improve the parsing expression.

Until we see that...

Two things about the match() function could be causing challenges with the parsing you describe:

  1. match() in automation rules does not handle linefeeds and carriage returns well, and so consider replacing / removing them with chained text functions before using match().  Tip: when you need to preserve the formatting, replace formatting characters first with a known expression such as "~~", perform the match, and then add the formatting back afterwards.
  2. match() produces a list of results, and so the split() you show is not needed...unless your Description contained linefeeds / carriage returns, in which case each line parsed would become an array in a list of results.  Removing the control characters should eliminate the need for handling the array syntax, and the split() can be removed.

Kind regards,
Bill

Vishal Thakkur March 28, 2024

Hi Bill, As described earlier my description would contain IP address it could be any type like Private IP or Public IP but there is no specific description it may change for every alert but IP address would be always there. 

Example Description - Srchost: 10.14.122.2
                                      MAC : 006648572879
                                      Domain :

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

Thanks for that information; I would first remove the newlines before trying the match.

 

Please also note, the documentation states: 

Screenshot 2024-03-28 072550.png

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--

Note that "is based on" as it does not specifically indicate what does / does not work for regular expression syntax.  Several other community posts have found regular expressions which work elsewhere do not work the same in automation rules. 

I encourage starting with the simplest expression that can possibly work, testing, and only then incrementally add more to handle edge cases, testing as you proceed.

0 votes
Kalyan Sattaluri
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 27, 2024

Hello @Vishal Thakkur 

Have you tried to remove those brackets..

{{issue.description.match(".*(\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b).*").split(",").distinct.remove("[").remove("]")}} 

Vishal Thakkur March 27, 2024

Yeah I tried that and instead of removing bracket it removed the value inside it and result was - [], []

Kalyan Sattaluri
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 27, 2024

LOL, sorry. I am sure other experts can share simpler solution but next thing I can think of is to create a variable and store current output in it and then do remove operation there.

if you create myvar variable = {{issue.description.match(".*(\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b).*").split(",").distinct}} 

then you can do {{myvar.remove("[").remove("]")}} to remove them and it will be comma separated values. Yes, the variable is a text string but when you send it in your payload in web request, it will operate as a list.

 

Suggest an answer

Log in or Sign up to answer