Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically log the work on jira ticket

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2020

Anybody has the script which can log the work automatically on the Jira ticket.

4 answers

0 votes
evzensx June 26, 2020

We are using Tempo Timesheets and for us this script in postfunction works just fine:

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import is.origo.jira.plugin.common.TempoWorklogManager
import com.tempoplugin.core.datetime.api.TempoDateTime
import com.tempoplugin.platform.api.user.TempoUser

@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModule

TempoWorklogManager tempoWorklogManager
TempoUser tempoUser
Long timeToLog = 300L //5min in seconds
Long timeSpent = issue.getTimeSpent() ? (issue.getTimeSpent()+timeToLog) : timeToLog
Long remaining = issue.estimate ? (issue.estimate - timeToLog) : 0 // calc remaining estimate if set
issue.setTimeSpent(timeSpent)
tempoWorklogManager.create(
issue.id,
TempoDateTime.now(),
"Auto-created worklog",
null, //attributes
timeToLog,
0L,
remaining,
tempoUser,
[:]
)
0 votes
Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2020

Thank you both for your suggestions.

As we are using script runner plugin so I worked on the script and its working fine as expected.

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 10, 2020

Hello,

below is the code working fine if i provided the start date and end date manually ..

 

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomField startDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(new Long(10250));
def startDateValue = issue.getCustomFieldValue(startDate)
log.error "Start Date : ${startDateValue}"
CustomField endDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(new Long(10251));
def endDateValue = issue.getCustomFieldValue(endDate)
log.error "End Date : ${endDateValue}"

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")
String startDateVal = sdf.format(startDateValue) //2018-04-21
String endDateVal = sdf.format(endDateValue)
log.error " After format : Start Date ${startDateVal} - End Date : ${endDateVal}"

def body = '''{
"worker": currentUser,
"comment": "auto work log.",
"started": startDateVal,//here if i add date manually then its working fine
"endDate": endDateVal, //here if i add date manually then its working fine
"timeSpentSeconds": 28800,
"originTaskId": "TEST-1",
"remainingEstimate": 0,
"includeNonWorkingDays": false,
"attributes": {}
}'''

what i am doing wrong here...anybody can help me out with this.

evzensx June 26, 2020

If it works fine when you add date manually, so I guess problem in types cast.

You need to find what type of data expected in "started" and "endDate" fields. I may be Date or something else but your variables is String.

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2020

Hey @evzensx 

It's my mistake, actually, I have fixed it but did not update here.

The issue is with worker..it accepts the user name/key in lower case. :)

0 votes
Poorvi Jhawar
Atlassian Partner
June 8, 2020

Hi @Yogesh Mude 

We have an app that does exactly this. EasyTime — An automatic time tracking app for Jira

It will log time as you work through your tickets, without having to start or stop a timer or changing the ticket status. 

It works on the relative priority of events which you can configure. It is a new app, and we would love you to give it a try and give us feedback. You can always reach us at support@techtime.co.nz with any questions :) 

 

Cheers

Poorvi

0 votes
Jack Brickey
Community Champion
June 8, 2020

have you considered any of these browser options?

jira-worklog-tool-chrome-plugin 

clockify-jira-time-tracking 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, aafp, jira migration, marketing collaboration, end siloed work, streamline workflows, kerrie gottschalk, jira cloud admins, unified marketing, process visibility, team efficiency, cross-team collaboration

How Kerrie Gottschalk unified AAFP’s marketing team with Jira

At the American Academy of Family Physicians, siloed marketing teams faced delays and duplicate work. Kerrie Gottschalk shook things up by moving the department to Jira, streamlining processes, boosting visibility, and sparking stronger collaboration.

Read the story
AUG Leaders

Atlassian Community Events