Hello,
I want to use validator of a transition to prevent creating the same sub-task with the same summary.
For that - I'm using the following simple scripted validator:
ScriptRunner workflow function - Simple scripted validator (condition apply).
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager def issueManager = ComponentAccessor.getIssueManager() Collection subTasks = issue.getSubTaskObjects() if(issue.isSubTask()) { def issueParent = issue.getParentObject() def parentSubTasks = issueParent.getSubTaskObjects() def currentSubTaskSummary = issue.getSummary() !parentSubTasks.find{it.getSummary() == currentSubTaskSummary} }
The problem is that I still see the option to use the transition even though I'm not expecting to see it with this validator.
Any idea?
Thanks,
Bar
Hello,
Validator do not hide transition buttons. They just check the input in the transition screen and can throw an error if the values are wrong.
What you are looking for are conditions not validators
Hi Alexey,
Thanks for your answer.
You are right! I got confused, but when I'm trying to use this script in the Conditions it still let me use the transition.
Do you know why?
Thanks,
Bar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Condition must return true or false. Your script does not return anything. Try like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
def issueManager = ComponentAccessor.getIssueManager()
Collection subTasks = issue.getSubTaskObjects()
if(issue.isSubTask())
{
def issueParent = issue.getParentObject()
def parentSubTasks = issueParent.getSubTaskObjects()
def currentSubTaskSummary = issue.getSummary()
if(parentSubTasks.find{it.getSummary() == currentSubTaskSummary}) {
return false
} else {
return true
}
}
return false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, but it still let me use the transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The transition button will be hidden only if your script returns false. Try to put log.error in your code before all return statements and see if your script returns false.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wrote this code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Logger
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
def issueManager = ComponentAccessor.getIssueManager()
Collection subTasks = issue.getSubTaskObjects()
log.info("Sub Task ID List: " + subTasks)
def flag = 0
for (int i=0; i<subTasks.size(); i++) {
def value = subTasks[i] as String
def issueSubTask = issueManager.getIssueObject(value)
if(issueSubTask.getSummary().contains("request")){
log.info("There is a Bundle branch request sub-task")
flag = 1
return false
}
}
log.info(flag)
if(flag==0){
return true
}
Even if I checked that the flag equal to 1 I still can click on this transition.
Do you know why?
Thanks,
Bar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for my mistake. If you want the transition button to be hidden , you should set passesCondition variable to false.
passesCondition = false
And your script should be like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Logger
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
def issueManager = ComponentAccessor.getIssueManager()
Collection subTasks = issue.getSubTaskObjects()
log.info("Sub Task ID List: " + subTasks)
def flag = 0
for (int i=0; i<subTasks.size(); i++) {
def value = subTasks[i] as String
def issueSubTask = issueManager.getIssueObject(value)
if(issueSubTask.getSummary().contains("request")){
log.info("There is a Bundle branch request sub-task")
flag = 1
passesCondition = false
}
}
log.info(flag)
if(flag==0){
passesCondition = true
}
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.
I have a similar request. I tried the first script but it did not work for me.
I have a post-function that creates a subtask on transition. However, it is possible to go back in the workflow and then complete the transition again, which creates a duplicate sub-task. How can I prevent a duplicate sub-task from creating if the transition/sub-task creation had already previously occurred?
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.