Automations - combine smart values

Matt November 20, 2023

Hi, I would like a Jira automation to remove leading and trailing quotation marks from a issue description. Currently I have something that works, but I recognise that it is too resource heavy, how can I combine these steps into one?

 

1) Trim leading whitespace/newlines: {{issue.description.trim()}}

2) Re-fetch issue data

3) Check if leading quotation mark: {{issue.description.startsWith("\"")}}

4) Remove leading quotaion mark: {{issue.description.substring(1)}}

5) Re-fetch issue data

6) Check if trailing quotation mark: {{issue.description.endsWith("\"")}}

7) Remove trailing quotation mark: {{issue.description.substringBeforeLast("\"")}}

 

Can this automation be simplified? 

1 answer

1 vote
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.
November 20, 2023

Hi @Matt 

Just to confirm, are you trying to remove only one leading and one trailing quotation mark, if they are present in your description field?

If so, have you tried using the match() function with a regular expression to do that in one step: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--

Kind regards,
Bill

Matt November 20, 2023

Hi Bill, 

Yes that is correct, when copying a cell from Excel it adds quotation marks around the value if the cell contains line breaks. Issue described here.

The output from excel that is pasted into Jira is:

"ABC

123"

 

There is also a new line added after the trailing quotation mark. I will take a look at the match function, but am not familiar with regular expressions to work this out quickly. Could it also work with the trailing new line? I also want to preserve quotation marks if any exist within the desired description.

 

thanks

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.
November 20, 2023

In my experience, the implementation of match() in automation rules has trouble with newlines and regular expressions.  And so a work-around for your scenario could be: replace the newlines with a token, perform the match, and swap the token back to newlines.

For example:

{{issue.description.replace("\n","~~").match("^\"?(.*?)\"?$").replace("~~","\n")}}

This one will:

  • replace any newlines with ~~
  • perform the match
  • swap the ~~ back to newlines

Please adjust / test this to meet your needs, and take a look at the documentation to learn about the rule implementation of regular expressions.

I just saw your comment about the extra whitespace, so after you test decide if you want to add a trim() call to help with that.

Like Stefan Salzl likes this
Matt November 20, 2023

Hi @Bill Sheboy ,

Thanks for your great response, but I have not quite solved my issue.

It seems your solution does not work when there are internal new lines in the description, even if they are replaced with ~~. It seems to break the match and the entire string returned is blank.

I've attached some troubleshooting I did (Note that audit log 6 is your full solution but is cut-off in the view) which I hope enables smarter minds then mine to solve this for me. The first screenshot is when the test description has no internal new lines, and the second screenshot is when there are internal new lines.

no internal new line.pnginternal new line.png

 

Edited twice to update the screenshots to make examples clearer

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.
November 21, 2023

I am confused by what you are posting: what is shown for log entry 6 (i.e., what I suggested) works as you asked to remove the outer quotation marks.  And I just tested and it does remove embedded newlines as well.  

And...if you use the expression I suggested, there should be no need for the conditions so that will simplify the logic to one step: edit issue on the description field.  For testing you can write to the log, but that will not show the newlines.

Please post the text you are attempting to parse as that may reveal what is happening.  And perhaps use the code formatting to ensure it reflects what you are using.

UPDATE: My testing showed that my expression does have a problem if there was a final quotation mark and the original text did not have embedded newline characters.

 

One more question: how are you importing the data?  When I just tried an import of a CSV file which contained quotation marks around a description with embedded newlines, the newlines were all removed completely, leaving no characters in their places.

Matt November 22, 2023

Hi @Bill Sheboy , thanks for the response.

Just want to confirm that you saw the two screenshots? The first screenshot shows that it works correctly when there are no internal new line the description, the second shows that #5 and #6 fail when there are internal new line.

 

The input description used can be seen best in #2 where I have replaced the new line with "~~". I think trying to write it in this comment will just get confusing when I attempt to describe the invisible new line at the end.

 

The import is done from a copy paste of an excel cell that contains a new line(using Alt+Enter).

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.
November 22, 2023

I did see the screen shots, and wondered if that was a long rule with an if/else condition or was multiple rule executions.  It appears to be different rule executions...with different Description values.

 

I also tested your #5 version, which essentially just drops the final replacement of ~~ back to newlines, and that worked for me.

When I create a sample file using Excel, using Alt-Enter to add the blank lines, and save to CSV, the CSV does contain the newlines.  After import, all newlines are removed: leading, trailing, and embedded.  The only way I was able to test was to edit the Description field.  This is why I asked how your import was performed.

 

At this point I have two possible hypotheses:

  • The rule is "glitched" as a result of too many edit / publish cycles, as this can sometimes break rules.  Two ways to check that are:
    • Disable your rule, wait a minute, re-enable, and retest it.  If that does not work...
    • Disable your rule, and re-create it with the simplest case possible: trigger on Description change and write #6 version to the log.  If that does not work...
  • Perhaps your Description field contains other characters we are not seeing
Matt November 23, 2023

Hi Bill, I put this down to the match function not working on multiple lines. Instead I am now using the below workaround. I only want to edit the description once as doing it multiple times was self-triggering the automation to run again(is there a way to stop this?).

 

excel quotes.png

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.
November 23, 2023

Please check the Rule Details section to see if the "Allow Rule Trigger" option is enabled.  If it is, disable that.

This option is normally used when one rule does some action that you want to trigger another rule.  It is disabled by default to prevent errors and run-away rule execution / looping.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events