Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

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

Vladislav
Contributor
October 4, 2019

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
Lady Di
Atlassian Partner
October 4, 2019

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

Vladislav
Contributor
October 4, 2019

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

Lady Di
Atlassian Partner
October 4, 2019

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

def commentText = transientVars.get("comment")
Like Vladislav likes this
Vladislav
Contributor
October 7, 2019 edited

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

 

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

def resVal = issue.resolution?.name

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events