How to parse a wiki style table in a multi-text field

So my friend @Mourad Marzouk asked in the Adaptavist forum:

But because Groovy makes my head hurt, I went ahead and posted an answer on how to do it with Automation, which well... probably belongs here.

Also, I think this is a simpler solution for this (if I'm interpreting the original question correctly):

The table we're splitting looks like this:

Old Part #

Old Rev

New Part #

New Rev

Part Description

Procurement/End Item

Part number 1

Old Revision 1

Part number 1

Revision 1

Description 1

End Item 1

Part number 2

Old Revision 2

Part number 2

Revision 2

Description 2

End Item 2

If you look at the wiki source for this table, it looks like this:

||*Old Part #*||*Old Rev*||*New Part #*||*New Rev*||*Part Description*||*Procurement/End Item*||
|Part number 1|Old Revision 1|Part number 1|Revision 1|Description 1|End Item 1|
|Part number 2|Old Revision 2|Part number 2|Revision 2|Description 2|End Item 2|

First you split the description by newlines: {{issue.description.split("\n")}}, and iterate through each line with the For each advanced branching.

Then for each line ({{row}}), if it doesn't contain || (header), but does start with a |, then create a new subtask.

part1.png

You then can split the row to get each "column", and those could be put in fields or whatever. I just threw them all in the Description.

First you split the description by newlines: {{issue.description.split("\n")}}, and iterate.

First column (Old part #) is: {{row.split("\|").get(1)}}

(Numbering starts with 0, but because the tables _start_ with a pipe character, we actually are getting the second column). Example:

0|1|2|3|4|5|6|
|Part number 1|Old Revision 1|Part number 1|Revision 1|Description 1|End Item 1|
part2.png
So you'll get sub-tasks for each of the content rows in the table, and if you wanted, you could populate fields with different column data.

Now this assumes that you only have one table per Description, and also that there aren't any other random lines that start with a | (pipe) character.

It might be safer to change the second comparison to exactly matches regular expression and use this:

 ^\|.*\|$ 
That will ensure that the line both starts and ends with a pipe character.

3 comments

Dave Liao
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2022

@Darryl Lee - the images aren't loading in this article FYI!

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.
May 7, 2022

Gah. Thanks. This is what happens when I try to copy-paste images here. Will fix in a bit. 

Like Dave Liao 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.
May 17, 2022

Good stuff, @Darryl Lee !

Another good pairing of techniques with that newline split is to add regEx and smart value, list filtering.  Now...if smart value, list filters also worked with smart value params and smart branches could produce objects...we'd have a lot more options  :^)

Kind regards,
Bill

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events