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

Update timeSpent field

Eduard Diez
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.
January 16, 2019

Can someone explain to me why my code is bad?

Merci

Captura3.PNG

I put my code:

 

def time = "1m"

def result2 = put("/rest/api/2/issue/${linkKey}")
.header('Content-Type', 'application/json')
.queryString("overrideScreenSecurity", Boolean.TRUE)
.body([
fields: [
worklog: [
worklogs:[
timeSpent: time
]
]
]
])
.asString()
if (result2.status >= 200 && result2.status < 300) {
logger.info('success 2')
} else {
return "${result2.status}: ${result2.body}"
}

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2019

Hi Eduard,

Thank you for your question above.

I can confirm that in order to log work on an issue that you need make a call to the Update Worklog rest API which Atlassian have documented here passing the parameters outlined on this page in order to update a worklog.

The rest endpoint that you are calling inside of your script is incorrect which is the reason why you are unable to add a worklog to an issue, and you will need to use the endpoint outlined in the API documentation page above to set a worklog on an issue.

I have created an example script which you can view here which shows how you can update the time spent value for a worklog on an issue and you will be able to take this example script and use it as a reference to create the script that you require to achieve your requirements.

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

Eduard Diez
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.
January 24, 2019

Thank's for the repository

Pritesh Jagani November 8, 2021

What did you use to import for put method?

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 9, 2021

Hi Pritesh,

If you are using ScriptRunner for Jira Cloud then you do not use any imports as ScriptRunner for Jira Cloud comes bundled with UniRest as mentioned in the documentation page located here.

Kind Regards,

Kristian

Pritesh Jagani November 9, 2021

Using data center. 

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 9, 2021

Hi Pritesh,

Thank you for your response.

This post here is around Jira Cloud so I would advise you to post a new answer tagged as Jira Data Center so someone familiar with ScriptRunner for Jira Data Center can advise on this.

In the meantime, I noticed the script Libray example located here provides an example of making rest requests using the server/ data centre version of ScriptRunner and covers Put requests which you may find helpful.

Regards,

Kristian

TAGS
AUG Leaders

Atlassian Community Events