Forums

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

JIRA: Fill Comment Template on workflow transitions

patman_y September 3, 2024

Hola Atlassians, 

I have seen several cases of adding a postfunction and/or using ScriptRunner to add a comment automatically after doing a transition, but my case scenario is different. 

I have a workflow transition "Rejected", which moves a ticket's status to "Rejected" 
That transition screen has 2 fields - a "Rejection reason", and a "comment" 
Depending on the "Rejection reason", I want to populate the comment with a pre-defined template,
AND I want to show an error if the comment was not edited (i.e. comment === comment_template)
 

Example: 
Rejection reason: Not reproducible
Comment template: 

"""
Status: Failed
Error: Unable to reproduce the error. 
Tested on version: {{VERSION}}
"""

 
and if the final comment matches the Comment Template, user shouldn't be able to go through the transition, and actually show an error "Comment not edited". 

 

I would appreciate your support on that, hoping to find a proper solution for this problem. 
Thank you!

5 answers

1 accepted

0 votes
Answer accepted
patman_y December 12, 2024

Answer on the issue: 
ScriptRunner's Behavior is definitely the correct way to handle it, but it wasnt working properly as I was using JEditor on Jira, rather than the default text editor for comments. 

After reaching out to JEditor's support team, they suggested I add the following CSS code in the JEditor Custom CSS section, and then I could use ScriptRunner Behavior properly:

/* JEditor support - ticket #3576 */
.wiki-edit.jeditor-original-container {
display: block !important;
visibility: hidden;
position: fixed;


Hope this helps others!

0 votes
Aditya Verma
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.
September 19, 2024

My suggestion would be a simple one:

On your "Reject" transition screen, just put 2 fields "Rejection reason" and "Tested on version"(do not put comment field here).

Once this is submitted, we can run an automation which will drop a dynamic comment on the ticket based on the values of these two fields.

Thanks,
Aditya

0 votes
Yavuz Selim
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 16, 2024

Hello @patman_y ,

I reached the community page through the advertisement you opened. I examined your request, it can be done with Behavior, but it will not be enough alone. Scripted Validator will also be required. Only then can the transition be allowed by checking whether the comment has been edited or not.
If you would like to get professional support on this issue, please be clear in the comment and I can refer to your ad.

Best regards, Yavuz

0 votes
Michael Bramhall September 4, 2024

This would be possible in behaviours in scriptrunner. Pseduocode that should achieve your use case.

  1. Create a behaviour associate with the correct projects and issue types that are applicable/or make global if system wide.
  2. Tag "Rejection reason" in the behaviour. Add a script
  3. Add a condition to the script that checks if present on the "reject" screen else this behaviour would trigger on each screen with "Rejection reason" present
  4. Use the following line to get the value of rejection reason field when it changes
    def rejectionReason = getFieldById(getFieldChanged()).getValue()
  5. Define the template of the comment such as
    def commentTemplate = "TODO"
  6. Get the field for comments
    def comment = getFieldByName("comments")
  7. Use conditions with the above define variables such as
    if(rejectionReason == "Example"){
    comment.setFormValue(commentTemplate)
    }

    Hope this helps
patman_y September 16, 2024

hey @Michael Bramhall 

here's my code: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager

// Get the value of the rejection reason field
def rejectionReasonField = getFieldById(getFieldChanged())
def rejectionReason = rejectionReasonField.getValue() as String

// Prepare the template based on the rejection reason
def commentTemplate = "DEFAULT VALUE"

switch (rejectionReason) {
case "Reason 1":
commentTemplate = """
Status: Rejected
Reason: Lorem ipsum 1
""".trim()
break
case "Reason 2":
commentTemplate = """
Status: Rejected
Reason: Lorem ipsum 2
""".trim()
break
default:
commentTemplate = "No specific reason provided."
}

// Set the Comment field value with the template
def commentField = getFieldById("comment")
commentField.setFormValue(commentTemplate)


and yet, the commentField doesnt get modified at all, even with the DEFAULT VALUE. 

Am I doing something wrong?

0 votes
Samuel Gatica _ServiceRocket_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 3, 2024

Hi @patman_y 

Welcome to the community!

Regrettably, this is not achievable using the native Jira tools.

You may be able to archive this with the Behaviours - ScriptRunner for Jira Cloud app.

 

Best regards

Sam

patman_y September 3, 2024

Hey @Samuel Gatica _ServiceRocket_ ! thank you for your reply

How would this be done with ScriptRunner Behaviours? I tried ChatGPT'ing it, but to no avail, unfortunately

Suggest an answer

Log in or Sign up to answer