It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to catch a comment from transition and resolution value with scriptrunner

Hi All,

Just stuck on searching a solution for following complex functionality:

When parent issue transitioned to status Resolved and it has Sub-tasks opened then all opened Sub-tasks should be transitioned to status Resolved as well and Sub-tasks should get resolution value that user chose on resolution screen while transitioning parent issue and if user adds a comment on resolution screen that comment should be added to Sub-tasks.

I've been searching google few days for this but could not find a solution how to catch comment that user enter on resolution screen on parent issue, and also no success to get resolution value that user choose on resolution screen on parent issue to paste it to Sub-tasks.

The code I could write with scriptrunner documentation just can transition sub-tasks when parent issue is transitioned and change sub-tasks resolution to pre-defined value and adds pre-defined comment. But it's not an option for us. Because if user does not enter any comment on transition this code gets last comment from the issue anyway..


Attaching my code below:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.config.SubTaskManager

Issue issue = issue
def constantManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
def cwdUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager()
Collection subTasks = issue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each { Issue it ->

def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager()
def commentCatch = commentManager.getLastComment(issue)
def text = commentCatch.body

String comment = "*Resolved* Last comment from the parent issue: $text";
def issueInputParameters = new IssueInputParametersImpl()

def doneResolutionId = constantManager.getResolutions().find {it.name == "Done"}?.id
def doneStatusId = constantManager.getStatuses().find {it.name == "Done"}?.id

issueInputParameters.setResolutionId(doneResolutionId).setStatusId(doneStatusId).setComment(comment)

def transitionValidationResult = issueService.validateTransition(cwdUser, it.id, 5, issueInputParameters)
log.debug("Validation result : ${transitionValidationResult.errorCollection}")
if (transitionValidationResult.isValid()) {
log.debug("Transition for sub task ${it.key} is valid")
issueService.transition(cwdUser, transitionValidationResult)
}

}
}
 

Thank you in advance for help or advise!

Jira Software 8.1.1 (Server)

Scriptrunner Version 5.5.6.1-jira8

1 answer

1 accepted

0 votes
Answer accepted

Те, если коммента нет, дочек не нужно резолвить, а если есть нужно?

Нужно резолвить в любом случае. А если еще и комментарий написали во время перехода, тогда этот комментарий нужно к каждому саб-таску прикрепить.

Получить коммент из перехода можно так.

def commentText = transientVars.get("comment")
Like Vladislav Polyutkin likes this

Спасибо! Прекрасно работает!

 

Нашел, как получить выбранное значение Resolution на переходе:

def resVal = issue.resolution?.name

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

363 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you