Forums

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

automation to edit comments - remove specific text and blank space

Carla Gonzalez April 22, 2025

when clients send an email, it's added as a comment in a JSM issue (work item).

since it's coming from an external source, the text "ATTENTION: Ce courriel provient d’une adresse externe. / This message originated outside Company Name." is added to the comment. 

I have the following rule, which removes that text from the comment: 2025-04-22_9-38-41.jpg

 

however, this leaves some empty space at the top of the comment: 2025-04-22_9-40-08.jpg

 

How could i remove this empty space? 

I have tried adding another THEN action with currentComment.body.trim() but it didn't work. it added the text that had already been removed by the previous action and didn't remove any empty space. i assume that currentComment hasn't been updated with the changes from my first action, how do i get access to the latest edited comment? 

 

any help is appreciated and thankyou in advance! 

2 answers

1 accepted

0 votes
Answer accepted
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.
April 22, 2025

Hi @Carla Gonzalez 

It is likely there is a newline, or a carriage return and a newline, at the front of the text.

After you have removed it, add a trim() function at the end of the expression to remove them.  The reason the characters cannot be added within the remove() function is because there are multiple ways that blank space could be created.

For example to remove that prefix:

{{comment.body.remove("your prefix text to remove").trim()}}

 

Kind regards,
Bill

Carla Gonzalez April 22, 2025

hi @Bill Sheboy thanks for the help :)

I've tried this out: 2025-04-22_14-09-38.jpg

 

but that space is still there in the comment: 2025-04-22_14-09-47.jpg

is there maybe another way to trim the blank space? 

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.
April 22, 2025

This is curious...and the trim() should remove the obvious whitespace characters.  I tested this repeatedly (with different formatting) with Jira Cloud and it worked as expected.

What version of Jira are you using: Cloud, Server, or Data Center?

 

Let's find out exactly what is left in there that is causing the extra spacing.  Before the comment edit, please add the Log action, and write this expression:

First character code: {{comment.body.remove("ATTENTION: Ce courriel provient d’une adresse externe. / This message originated outside Company Name.").trim().left(1).urlEncode()}}

That will remove your prefix, extract the first character, and display its character code in the log.

Carla Gonzalez April 23, 2025

Hey @Bill Sheboy

I have added the log action before the edit comment action as such: 2025-04-23_8-32-24.jpg

And this is the log: 

2025-04-23_8-32-08.jpg

a brief google search indicates this is an opening curly bracket? I don't see this anywhere... I tried adding it to the text that is removed but it didn't remove that empty space. 

thank you again so much for your help! already learning a ton, 

Carla

Carla Gonzalez April 23, 2025

i forgot to mention that I'm using Jira Cloud. 

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.
April 23, 2025

I agree: there does not appear to be a left-curly bracket in that comment text.

The last thing to try is immediately after the trigger, log the entire comment to evaluate what it shows, comparing that to what you are checking:

full comment body: >>{{comment.body}}<<

I added some surrounding greater-than and less-than characters to help us see if there is anything else at the front or back.

 

If that contains exactly what you expected with no extraneous characters, I recommend asking your Site Admin to check with the Atlassian Support team to learn what they suggest: https://support.atlassian.com/contact/#/

Carla Gonzalez April 23, 2025

@Bill Sheboy 

aha! there's some color coding! 2025-04-23_14-45-29.jpg

when seeing this message in outlook, it looks like: 2025-04-23_14-46-08.jpg

this explains why the trim wasn't working! 

I've tried to add those characters to the .remove string but it didn't work. I guess it's cause they're "invisible". do you know if there's a way to convert those to text? 

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.
April 23, 2025

Awesome!  Let's try to remove the markup with the .text function:

{{comment.body.text.remove...}}

If that does not help, we will need to resort to a regular expression and the replaceAll() function to remove your prefix text.

Carla Gonzalez April 23, 2025

THAT WORKED!!!! 

YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

Like Bill Sheboy 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.
April 23, 2025

Awesome; I am glad to learn it is working now! 

Please consider marking this question as "answered" to help others with a similar need find solutions faster.  Thanks!

Carla Gonzalez April 24, 2025

done! thanks again for the help :)

0 votes
Anthony Morais
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.
April 22, 2025

Hi @Carla Gonzalez 

I ran a test and got it working by using this smart value in the "Edit comment" action:

{{currentComment.body.remove("ATTENTION: Ce courriel provient d’une adresse externe. / This message originated outside Mira Geoscience.\n").trim()}}


Let me know if this works on your side too!

Carla Gonzalez April 22, 2025

hi @Anthony Morais thanks for the quick reply! 

I've tried {{currentComment.body.remove("ATTENTION: Ce courriel provient d’une adresse externe. / This message originated outside CompanyName.\n").trim()}}

but it doesn't seem to have correctly found the text in the comment, since it didn't remove it from the comment: 2025-04-22_10-10-18.jpg

I removed \n and this time it did find it and removed it: 2025-04-22_10-10-19.jpg

but the trim seems to not have done anything. do you know why that may be? maybe i could use something other than trim? 

Suggest an answer

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

Atlassian Community Events