Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I append additional content to the Comment field during transition?

Szymon Trocha July 23, 2019

Hi all,

I'd like to do the following:

- my transition screen has two fields: MyField (custom text field) and usual Comment field (built in)

- during transition the content of MyField and Comment is used to send an email via post function. This works fine.

- at the same time when this comment is added to issue I'd like it to be a concatenation of the Comment field and MyField entered during transition.

I have the following script to populate comment:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("MyField_name")
def CfValue = issue.getCustomFieldValue(cf)

// Get the current logged in user
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Get access to the Jira component manager and comment
def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment(issue)

// Get the comment, the user added in the form
def currentComment = transientVars.comment as String

// Define the body of the new comment
def newComment = "Additional comment: " + CfValue + "\nOriginal comment: " + currentComment

// Generate new comment
if (issue) {
commentManager.create(issue, user, newComment, false)
}

 

The post-function is added AFTER "Add a comment to an issue" and BEFORE "Update change history for an issue". However as a result I got two comments cretaed in the issue after this transition:

1. first contains original comment entered in the Comment field during transition

2. second contains an appended comment

How do I have only the second one injected and not both?

Thank you in advance!

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events