Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

How to change the "Time Logged" field via groovy?

Hi,

For some reason (potential workaround for issue described here ) I would like to be able to change the "Time Logged" field.

I have been able to change the "Time Logged" field only via the MutableIssue.store() method, but neither by using the IssueManager.upateIssue() method nor the IssueService.update() method.

Obviously I do not want to use the MutableIssue.store() method because it has been deprecated.

Any hint? 

MutableIssue.store() - Works

IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("TASKTEST-315")
ApplicationUser user =  ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

Long val = 3600 * 4


issue.setTimeSpent(val)
issue.store()

 

IssueService.update() - Does not work

IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("TASKTEST-315")
ApplicationUser user =  ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueService issueService = ComponentAccessor.getIssueService()

Long val = 3600 * 4

IssueInputParameters inputParameters = issueService.newIssueInputParameters()
inputParameters.setTimeSpent((Long)(val/60))
IssueService.UpdateValidationResult validationResult = issueService.validateUpdate(user,issue.id,inputParameters)
issueService.update(user, validationResult)

 

 

IssueManger.updateIssue() - Does not work

IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("TASKTEST-315")
ApplicationUser user =  ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

Long val = 3600 * 4


issue.setTimeSpent(val)
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,false)

3 answers

I usually use IssueManager.updateIssue(), but it is better to use this one because it is compatible JIRA6 and 7:

ComponentAccessor.getIssueManager().updateIssue(
        ComponentAccessor.getJiraAuthenticationContext().getUser()
        , issue
        , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build()
)

Also check that you have permission to log time?

You could get more information about errors into atlassian-jira.log.

Hi Vasiliy, thank you for your answer. I tried the code that you suggested, but it did no work. As per my original post, the only method that I have found being successful so far is MutableIssue.store(). The code that you suggested works fine if I want to change other fields (e.g. summary), but it does not work when I want to change the "TimeSpent" (TimeLogged) field.

I have checked and verified that I have the permissions to log time.

Neither atlassian-jira.log nor catalina.out report any error when I execute your code.

Thanks.

Could you check as admin that you have a permission to log time for issue?

Was there any solution? I am having the same problem with "Time Logged" changing.  issue.store() works fine, but it's depricated.

Hi. Same problem and same solution (use deprecated issue.store() methos)
Any news?

You should use this instead of issue.store():

ComponentAccessor.getIssueManager().updateIssue(
        ComponentAccessor.getJiraAuthenticationContext().getUser()
        , issue
        , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build()
)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

Bitbucket Pipelines Runners is now in open beta

We are excited to announce the open beta program for self-hosted runners. Bitbucket Pipelines Runners is available to everyone. Please try it and let us know your feedback. If you have any issue...

495 views 10 8
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