Groovy script - Auto comment based on time.

Hi All,

I'm trying to add a comment to issue when an issue transition happens at a specific time (between 8:30 to 10:00) in a day. Below my script,

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category

def date = new Date()
def formattedDate = date.format('hh:mm') (formattedDate)

SNGStart = "8:30" (SNGStart)

SNGEnd = "10:00" (SNGEnd)

if (formattedDate > "SNGStart" && formattedDate < "SNGEnd" ) {

String currentUser = "jira-admin"
commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commmgr.create(issue, currentUser, "Comment automatically generated!! (test)", true)

There is no error on logs but not getting excepted result. Could you please help me to correct this one?

Many thanks in advance.


Sanu P Soman

3 answers

You should create a transition which works with Date objects. Currently you're trying to use Strings to compare times, that's not a good idea.

Can you please guide me how it is? Currently I'm running this script at create transition.

Additionally make sure, your postfunction is the last postfunction in the list, after the issue is created. You don't need to call, a commentManager.create() is enough to create the comment.

It's always a good idea to include logging in your scripts to see what's happening. You could write

log.debug "Current date matches."

or similar to see if your script does what you expect. Make sure you set the log level to debug before that.

import org.apache.log4j.Level

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Jira

Updates to give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

324 views 1 12
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