Log work with groovy script issue

Hi

Here is a code:

CM = ComponentManager.getInstance()
worklogManager = CM.getWorklogManager()

for(int i=0; i<=4; i++) {
    worklog = new WorklogImpl(worklogManager, issue, null, issue.reporter.name, issue.summary, new Date(), null, null, 1*3600)
    worklogManager.create(issue.reporter, worklog, 0L, false)
}

OR

for(int i=0; i<=4; i++) {
    params = WorklogInputParametersImpl
        .issue( issue )
        .startDate(new Date())
        .timeSpent('1h')
        .comment('123')
        .buildNewEstimate()

    result = wls.validateCreate( context, params )
    wls.createAndAutoAdjustRemainingEstimate( context, result, true )
}

And here is a result:

5 worklog entries, with 1 hour spent
but Logged: shows only 1 hour instead of 5 hours

latest script runner addon with JIRA 6.1
same results with JIRA 5.1.7

Any ideas?

Thanks!

Sergey

6 answers

1 accepted

This widget could not be displayed.

Solution is to calculate logged time manually

for(int i=0; i=4; i++) {
    worklog = new WorklogImpl(
        worklogManager,
        issue,
        null,
        issue.reporter.name,
        issue.summary,
        new Date(),
        null,
        null,
        1*3600
    )
    worklogManager.create(issue.reporter, worklog, 0L, false)
    issue.timeSpent = issue.timeSpent == null 
        ? 1*3600 
        : issue.timeSpent + 1*3600
}

Hi @Sergey L1, I know this was from a while ago, but I just noticed your code is an infinite loop as you need i==4, not i=4, so it may be worth updating your comment. 

This widget could not be displayed.

Probably some kind of jira bug. As you see in the work log tab all the entries are there.

I've seen similar bugs where it barfs if there is not at least a one second difference in the creation time. In this case though I tested that and it still didn't work. Maybe for some reasons it assumes that they're all the same entry.

This widget could not be displayed.

Do you know any way to update estimated time?

This widget could not be displayed.

What come to my mind: These work log entries are all at the same time. What if you use a startDate that differs in at least one hour for each?

This widget could not be displayed.

Hermann
The same results when "startDate" are differs
Anyway, "Logged" field should be calculated properly even if dates are the same

This widget could not be displayed.

I am creating a issue and PostFunction like to get the value of the "Data da tarefa " (Type: Date Time) and "Tempo gasto" (Type: Number field) to automatically make a worklog.

 

Can you help me how can I do?
I'm not a developer and I have difficulties:

si-573.PNG

I would like to create the task the timestamp was:
Day 10 / February / 2015 and 3 hours worked

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

83 views 1 0
Join discussion

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