Forums

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

How do I replace text in the last comment posted?

Carla Pasquali
Contributor
October 15, 2020

Hello,

 

I am trying to setup a new rule using Automation for Jira where for any text that matches certain strings, it'll replace this with another text in the comments section:

1) This is my rule and I validated the regex at regex101.com successfully:

Screen Shot 2020-10-15 at 11.30.18 AM.png

2) It then edits the comment field and replaces anything that contains "Nm" : "text" with "":

Edit Issue:

 {
"update": {
{{issue.comments.last.body.replace("\Nm": "([^"]+)\", "")}}
}
}

 

However my rule is failing with the following message:

Edit Issue:

Error while rendering additional fields.Failed to get value for issue.comments.last.body.replace("\Nm": "([^"]+)\", "")

 

I've added a Log Action to my rule and it captures the comment successfully:

Issue comment is: {{issue.comments.last.body}}

Log Action:

LogIssue comment is: {{"PstlAdr": { "Ctry": "BRA", "AdrLine": "Avenida a",dafasdf "TwnNm": "Coa",sdfasdf "CtrySubDvsn": "RadsfadsfasdfO", "PstCd": "00000" }, "CtctDtls": { "Nm": "OaA", "PhneNb": "asdfasdfadsf" } }, "PmtId": { "InstrId": "adsfadsf" }, "PmtTpInf": { "CtgyPurp": { "Prtry": "B" } }, "Purp": { "Prtry": "" }"created_at": "2020-08-06T16:30:25.21Z"}}}

 

Not sure what the issue could be as the regex matches the correct expression in the comments section.

 

Any ideas on how to fix this?

 

Thanks!

2 answers

1 accepted

0 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 20, 2020

Hi Carla,

Automation in Jira does not yet support the ability to edit comments.  There is a related thread about this topic over in https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Automation-for-Jira-Can-i-Edit-a-Comment-of-an-Issue/qaq-p/687821 in which Andreas references an existing ticket to track that request over in https://codebarrel.atlassian.net/browse/AUT-419.

Comments are not quite like any of the other fields on an issue in Jira.  As such automation does not exactly have a means to edit existing comments just yet.  Perhaps you could use automation in order to change some other field on the issue in this manner, but for the time being the comment field works differently in this regard.

I hope this helps.

Andy

Carla Pasquali
Contributor
December 16, 2020

Thanks Andy. I have been able to get this to work using regex in Automation for Jira.

Like Marvin Brand likes this
1 vote
Trang Ngoc Nguyen March 1, 2023

I have faced the same problems and couldn't find the answers from multiple community posts, so just want to leave a working solution here for somehow who is also struggling:


{
"update": {
"comments": [
{
"edit": {
"id": "{{comment.id}}",
"body": "{{comment.body.substringBefore(\"Fra:\")}}"
}
}
]
}
}

 

This solution is following the JIRA REST API documentation.

Suggest an answer

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

Atlassian Community Events