Hello,
I have two validators on my workflow
First (Simple scripted validator) checks the number of comments and if the number of comments is less than 1 you cant close the issue.
Second
Require a comment on the transition
This validator enforces a comment is provided on transition.
Less than one comment, please comment
So if the first is true the second should appear, if it's false I should skip it.
If I put the first validator as a condition, not validator it will block/hide the transition, I want the transition to be visible, but to "activate" the validator only when the number of comments is less than 1
Thanks in advance,
BR, Olga
I see what you need ... If there are no comments on the issue already, one must be provided when closing.
You can achieve this with just your simple scripted validator. You will need to check both the number of comments on the issue if <1 then also check the presence of a comment in the transition.
...
return commentCount > 0 || transientVars['comment']
This will not, however, show that the comment is required when you are viewing the transition screen. Just if the validation fails will you know it was required.
If that's important for you, then you could use Behaviour instead of (or in addition to) your workflow validator.
In the Behaviour script, you can count existing comments, and if >0 then issue the command:
getFieldById('comment').setRequired(true)
Hello @PD Sheehan
Figured it out, thanks.
The tricky part was to make validator not apply to users of a specific group, I'll post my script so you can correct if something is wrong, but it works.
BR, Olga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the working script
The validator bypasses the users that are part of "Workflow validator bypass group"
Same can be applied to project roles.
import com.atlassian.jira.component.ComponentAccessor
def PassingCondition() {
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentManager = ComponentAccessor.commentManager
def comments = ComponentAccessor.commentManager.getComments(issue)
def numberOfComment = commentManager.getComments(issue).size() >=1
def UserMemberOfBypassValidatoGroup = ComponentAccessor.getGroupManager().getGroupsForUser(currentUser)?.find {it.name == "Workflow validator bypass group"}
def Condition_1 = numberOfComment || UserMemberOfBypassValidatoGroup || isUserMemberOfRole ('Team Lead')
if (Condition_1){
return true;
}
}
if (PassingCondition()){
return true;
}
else { transientVars["comment"] }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can probably simplify this a bit.
import com.atlassian.jira.component.ComponentAccessor
def hasComments() {
ComponentAccessor.commentManager.getComments(issue).size() >=1
}
def isUserInBypassGroup() {
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def bypassGroup = 'Workflow validator bypass group'
ComponentAccessor.groupManager.getGroupsForUser(currentUser)?.any{it.name == bypassGroup}
}
transientVars["comment"] } || hasComments() || isUserInBypassGroup() || isUserMemberOfRole ('Team Lead')
In a series of "or" like this, the first true result causes the whole line to be true and the rest of the line is not evaluated. So by doing it this way, you are always evaluating the fewest number of elements.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @PD Sheehan
Thanks a lot, my knowledge on grovy is "beginnger"
Also tested it and your code works, just edit the part in the last line there is one unnecessary }
BR, Olga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Olga Videc ,
You can condition in your validator only. Validation will happens, if your condition is true. You can update your second validator.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.