How to Create a Worklog Entry by Postfunction

Hi,

we need a post function creating a worklog entry. I found https://answers.atlassian.com/questions/11290 and translated that to groovy:

cfo = componentManager.getCustomFieldManager().getCustomFieldObjects(issue).find {it.name == 'StartTime'}
cfv = issue.getCustomFieldValue(cfo)
dt = ((int)((t0.getTime()-cfv.getTime()+30000)/60000)).toString()+"m"
WorklogInputParametersImpl.issue(issue).startDate(cfv).timeSpent(dt).comment( "Autologged "+dt+".").buildNewEstimate(); componentManager.getInstance().getIndexManager().reIndex(issue)

The code does not throw any error - but there is no additional worklog entry - what do I have to add? Or which recipe do I have to follow?

Thanks in advance

1 answer

1 accepted

1 vote
Henning Tietgens Community Champion Mar 08, 2012

I use this closure to create worklog entries:

logWork = { issueKey, date, timeSpent, comment, currentUser ->
	myIssue = issueManager.getIssueObject(issueKey)
        Long timeSpentSeconds = timeSpent*3600
	newWorklog = new WorklogImpl(worklogManager, myIssue, null, currentUser.name,
                   comment, Date.parse('dd.MM.yyyy hh:mm', date), null, null, timeSpentSeconds)
	worklog = worklogManager.create(currentUser, newWorklog, null, false)
}

You have to use worklogManager.create(). worklogManager you get from ComponentManager.instance.worklogManager.

Thank you Henning. With help of a java-familiar colleague we solved the issue using this groovy code:

  import com.atlassian.jira.issue.worklog.WorklogImpl
...
cus = componentManager.getJiraAuthenticationContext().getUser() jud = new java.util.Date(cfv.getTime()) wli = new WorklogImpl(null, issue, 0, cus.name, "Autologged "+dt.toString()+".", jud, null, null, dt) ComponentManager.instance.worklogManager.create(cus, wli, 0, false)

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 Jul 10, 2018 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...

182 views 0 4
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