Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Create/update Worklogs within a Plug-in

fla_91 August 21, 2016

I develop a Plug-in that creates or updates a worklog if needed.

 

I can create worklogs with this code:

Booking booking;	// object i receive from a web service

if(issue != null) {
            WorklogInputParameters parameters = new WorklogInputParametersImpl.Builder()
                    .issue(issue)
                    .startDate(booking.getBookingDate())
                    .timeSpent(formatToMinute(booking.getTime()))
                    .comment(booking.getDescription())
                    .build();
            
            ApplicationUser user = userManager.getUserByKey(booking.getEmployeeShortcut());
            if(user != null) {
                JiraServiceContextImpl jsci = new JiraServiceContextImpl(user);
                WorklogResult result = worklogService.validateCreate(jsci, parameters);               
                worklogService.createAndAutoAdjustRemainingEstimate(jsci, result, true);
            }
        }

 

but i always get an error in the log:

java.lang.UnsupportedOperationException: Cannot set or mutate an ImmutableGenericValue

and the time tracking "Remaining" and "Logged" doesn't change its value. I think the error refers to that.

 

i think i have to change the last line "worklogService.create...()" but i also tried the other methods but they also didn't work.

updating a worklog also doesn't work.. i think there I have the same problem

 

thanks a lot smile

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
fla_91 August 23, 2016

I solved it myself.. I used MutableIssue instead of Issue, than it works.. see code below:

if(issue != null) {
	MuableIssue mutableIssue = issueManager.getIssueObject(issue.getId());

	WorklogInputParameters parameters = new WorklogInputParametersImpl.Builder()
            .issue(mutableIssue)
			...
	}
0 votes
fla_91 August 22, 2016

Updating works fine, but on creating i always get the error above.. the worklog creates but it doesn't set the new remaining estimate.

for updating i use this code:

WorklogInputParameters parameters = new WorklogInputParametersImpl.Builder()
                            .issue(issue)
                            .worklogId(booking.getWorklogID())
                            .startDate(booking.getBookingDate())
                            .timeSpent(formatToMinute(booking.getTime()))
                            .adjustmentAmount(formatToMinute(booking.getTime()))
                            .comment(booking.getDescription())
                            .build();
                    
                    ApplicationUser user = userManager.getUserByKey(booking.getEmployeeShortcut());
                    if(user != null) {
                        JiraServiceContextImpl jsci = new JiraServiceContextImpl(user);
                        WorklogResult result = worklogService.validateUpdate(jsci, parameters);
                        worklogService.updateAndAutoAdjustRemainingEstimate(jsci, result, false);
                    }
TAGS
AUG Leaders

Atlassian Community Events