How to display a comment dialog using ScriptRunner Validator?

Tom L May 31, 2018

I have a requirement in which the comment dialog should be shown during a workflow transition if the current user did not previously provide a comment. 

Is there any JIRA APIs that can be used in the ScriptRunner Validator to display a comment dialog for the user to enter comments?

Thanks,

Tom

 

2 answers

1 accepted

0 votes
Answer accepted
Ivan Tovbin
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.
June 1, 2018

Hi Tom,

You don't need Scriptrunner for this. Simply add a screen to your transition. Check out this documentation for more info.

Tom L June 1, 2018

Thanks Ivan.

I have no issue posting the comment dialog on transition by adding a screen and using the "Comment Required Validator (JMWE add-on)" Validator, but this is not what I am trying to achieve.

The use case that I am trying to achieve is to post the comment dialog only if the last comment was not added by the user doing the transitioning.

For example, if the last comment added is from the same user that wants to progress the issue to the next state, no comment dialog appears for the transition.  If the last comment is from a different user, a comment dialog appears before allowing the transition.

I believe through ScriptRunner, we can obtain the user who added the last comment, but is there an API to invoke the comment dialog (which is a transition screen)?

Any hint or direction to implement this use case is appreciated.

Thanks,

Tom

Ivan Tovbin
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.
June 3, 2018

Ah, I see. Thank you for the clarification. This is totally doable. What I would do, if I had a similar issue is I would created TWO transitions, one with a comment screen and one without. Then I would configure two conditions, one for each transition. One condition would show the transition WITHOUT a comment screen only if the author of the latest comment is the current user. And the other condition would show the transition WITH a comment screen only if the author of the latest comment is NOT the current user. 

As for the conditions themselves you can even use JMWE to write a scripted condition which would check the author of the latest comment against the current user.

If you need help with the scripts please do let me know, I might be able to help.

Tom L June 4, 2018

Hi Ivan,

Thank you for your advice.

Based on your suggestion, assume transition "A_B" doesn't have the comment screen, and transition "A__B"  has the comment screen.  Now lets assume the condition is fulfilled where the author of the latest comment is NOT the current user so the transition button "A__B" is shown.  Clicking on "A__B" will show the comment screen.

But what if there's a scenario where the current user added a comment and then clicked on "A__B".  In this case, the author of the latest comment is the current user so clicking on "A__B" will show the comment screen which we do not want.  How do we bypass the comment screen at this point?

Also, any pointer on writing the scripts for the conditions is appreciated.

Thanks,

Tom

Ivan Tovbin
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.
June 5, 2018

If the current user will add a comment BEFORE clicking on the transition button the the condition for a transition WITHOUT a screen will be met and it's button will appear. At the same time, the condition for a transition WITH a screen will no longer be met and so it's button will disappear.

As for the scripts, here's the code for both cases.

Transition WITH a screen:

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueComments = ComponentAccessor.getCommentManager().getComments(issue)

if (issueComments[issueComments.size()-1].getAuthorApplicationUser().equals(currentUser)){
return false
}
return true

 

Transition WITHOUT a screen:

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueComments = ComponentAccessor.getCommentManager().getComments(issue)

if (issueComments[issueComments.size()-1].getAuthorApplicationUser().equals(currentUser)){
return true
}
return false
Tom L June 6, 2018

Thanks Ivan.  Your solution works very well.

0 votes
Tom L June 1, 2018

Accidently answer instead of reply.

Suggest an answer

Log in or Sign up to answer