It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy script - Auto comment based on time.

Sanu Soman Nov 17, 2013

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')
log.info (formattedDate)


SNGStart = "8:30"

log.info (SNGStart)

SNGEnd = "10:00"

log.info (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)
issue.store()
}

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

Many thanks in advance.

Thanks,

Sanu P Soman

3 answers

0 votes
Henning Tietgens Nov 17, 2013

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.

Sanu Soman Nov 17, 2013

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

0 votes
Henning Tietgens Nov 17, 2013

Additionally make sure, your postfunction is the last postfunction in the list, after the issue is created. You don't need to call issue.store(), 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
log.setLevel(Level.DEBUG)

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

2,448 views 6 15
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you