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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,462,434
Community Members
 
Community Events
176
Community Groups

Update timeSpent field

Edited

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

1 vote
Answer accepted

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

Thank's for the repository

What did you use to import for put method?

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

Using data center. 

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events