I am attempting to write a bit of code that will be used as a scriptrunner postfunction. The goal is that when an issue gets transitioned all of the comments get deleted.
So far I have come up with this
delete("/rest/api/2/issue/22718")
.header("Content-Type", "application/json")
.body([
fields:[
comment
]
])
but I get an error about the comment
CorrelationId: 894d7210-838d-4549-b5ea-cf7bbb005c07 RUN Script identifier: 9e6a3000-0bd1-4fa4-9545-d301488a8259 Took: 100ms Logs: 2019-12-26 23:20:37.553 ERROR - No such property: comment for class: Script1 on line 4 2019-12-26 23:20:37.572 ERROR - Class: com.adaptavist.sr.cloud.events.ConsoleScriptExecution, Config: [:]
What am I doing wrong here? Im having trouble finding information about deleting with scriptrunner.
Ive also looked at the atlassian documentation and the delete comment command but I dont really understand how to translate the api request into a scriptrunner script.
any help would be appreciated.
Can you include your script so we can take a look?
Hi Bryan,
This is what I was trying
delete("/rest/api/2/issue/22718")
.header("Content-Type", "application/json")
.body([
fields:[
comment
]
])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alex Piwowar ,
Apologies for the delay, please do check the script I have attached.
Pseudo code:
def response = get('/rest/api/3/issue/TP4-1/comment').header('Content-Type', 'application/json').asObject(Map)
def comments = response.body.comments
if(comments){
comments.each{
delete(it.self.toString()).header('Content-Type', 'application/json').asObject(Map)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh wow that worked, thanks.
May I ask, how do you figure all of this out?
In the first line what does the .header do? and the Map?
Where do you the it.self from in the loop?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alex Piwowar ,
I referred the ScriptRunner cloud documentation.
https://scriptrunner-docs.connect.adaptavist.com/jiracloud/
It should help you if you want to integrate additional functionality using ScriptRunner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.