Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Reading result data from asynchronousTaskResult (IssueService.clone() api method)

Bhaskara Yandava July 3, 2018

I have a groovy script that clones an issue using issueService.clone(user, validationResult) method. I am unable to find a way to read the result or handling the task completion notification from the current documentation. My use case is to wait until the clone operation is complete and get the clone issue key/object.

Any help is appreciated.

1 answer

1 accepted

1 vote
Answer accepted
Mark Markov
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.
July 3, 2018

Hello @Bhaskara Yandava

The thing is, that issueService.clone() itself returns AsynchronousTaskResult that have method isValid() which returns results of clone.

ref 

https://docs.atlassian.com/software/jira/docs/api/7.2.1/com/atlassian/jira/bc/issue/IssueService.html

And here is some example for you

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("some_custom_field_object")
Map<CustomField, Optional<Boolean>> map = [:]
map.put(cf, Optional.of(true))
def issueService = ComponentAccessor.getIssueService()
def issueCloneValidationResult = issueService.validateClone(user, issue, "Some summary", true, true, true,map)
if (issueCloneValidationResult.isValid()){
def cloneResult = issueService.clone(user, issueCloneValidationResult)
if(cloneResult.isValid()){
log.error("Clone successful")
}
else{
log.error("There are some errors during cloning"+ cloneResult.getErrorCollection().getErrorMessages())
}
}

Hope it helps!

Bhaskara Yandava July 3, 2018

Thank you for your quick reply Mark. isValid() is only providing me the status of the operation. From the esult object I am able to get only the task id but not any issue key or id. Is there a way to collected that information? 

Mark Markov
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.
July 3, 2018

I ve made little research and it seems you can't.

But you can use IssueFactory to clone issues instead of IssueService.

Please check my answer bellow

https://community.atlassian.com/t5/Jira-questions/Clone-subtasks-from-other-issue-using-Groovy/qaq-p/826666?utm_source=atlcomm&utm_medium=email&utm_campaign=immediate_general_reply&utm_content=topic

Suggest an answer

Log in or Sign up to answer