# Jython - Creating Worklog object

**URL:** <https://community.developer.atlassian.com/t/jython-creating-worklog-object/3240>\
**Category:** Jira Development\
**Tags:** workflow, jira, jira-server\
**Created:** [May 1, 2017, 2:41pm UTC](https://community.developer.atlassian.com/t/jython-creating-worklog-object/3240 "2017-05-01T14:41:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mor](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@mor](https://community.developer.atlassian.com/u/mor)\
**Post date:** [May 1, 2017, 2:41pm UTC](https://community.developer.atlassian.com/t/jython-creating-worklog-object/3240/1 "2017-05-01T14:41:31Z")

</div>

Hi,

We are trying to get Worklog updated on a post function transition through one of our workflows.  
Currently we managed to get the time spent field updated, but we are having trouble getting the whole worklog object and completing it.  
Please see below the current Jython code we have:

```auto
from com.atlassian.jira.component import ComponentAccessor
from com.atlassian.jira.issue import Issue
import com.atlassian.jira.issue.history.ChangeItemBean

times=[]
diff=[]
user = ComponentAccessor.getJiraAuthenticationContext().getUser()
utils = ComponentAccessor.getJiraDurationUtils()
locale = ComponentAccessor.getLocaleManager().getLocaleFor(user)
changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

firstStart=changeHistoryManager.getChangeItemsForField(issue, "status")
for y in firstStart:
  if y.getToString()=="Handling":
    times.append({'s':"start", 't': y.getCreated().getTime()})
  if y.getFromString()=="Handling":
    times.append({'s': "end", 't': y.getCreated().getTime()})

times=sorted(times, key=lambda t: t['t'])
for t in times:
  if t['s']=='start':
    r=t['t']
  if t['s']=='end':
    diff.append(t['t']-r)

total=reduce(lambda x,y: x+y, diff)
issue.setTimeSpent(total/1000)

```

Thanks for any assistance!
