Set comment on workflow postfunction

Hi There,

I have requirement to automatically comment custom text with date & time and user who performed that workflow transition. I have searched and wrote a groovy script but it comments only the string (custom text) and does not comment the date/time and user who performed the transition. Could you help me in editing the script to required output.


import com.atlassian.jira.ComponentManager

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

import com.opensymphony.workflow.WorkflowContext

import org.apache.log4j.Category

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.fields.CustomField

import java.sql.Timestamp

import java.text.DateFormat

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

def plainFormatter = DateFormat.instance

currentDate = plainFormatter.format(today)

compManager = ComponentManager.getInstance()

CommentManager commmgr = compManager.getCommentManager()

commmgr = (CommentManager) compManager.getComponentInstanceOfType(CommentManager.class)

commmgr.create(issue, currentUser, "performed review at", currentDate, true)

Requried output:

username performed review at current date/time

Note: By removing import java.sql.Timestamp & java.text.DateFormat and currentDate in commgr.create, I was able to get only "performed review at" commented. When I include them I do not get any texts commented.

1 answer

0 vote

All this is available in the history tab, so just seems like unnecessary duplication.

Even if you need a comment, then people can see the time and user of the comment, and you don't need to worry about user timezones.

If you really want the current date you can use:

new Date().format("dd MMM yyyy")

Try it in the script console. I don't see where you've defined "today" amongst other problems.

If you want to fix your script you probably just need:

def today = new Date()

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

108 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you