Can someone explain to me why my code is bad?
Merci
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}"
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.