Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted (Groovy) Validator (JMWE add-on)

Rahul Krishna Vangara
Contributor
May 29, 2019

Is there a way to show , which sub-tasks custom fields are not filled as a validation message in the workflow validations, we are currently using Scripted (Groovy) Validator (JMWE add-on).

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Category
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.config.SubTaskManager
import com.opensymphony.workflow.InvalidInputException

SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects();
def Issues = "Please update the Below subtasks Statuses \n"
if (subTasks.isEmpty())
return false;
for (currIssue in subTasks)
{
if(issue.getStatus().name != "In Progress")
Issues = Issues + currIssue + ","
else
return true;
}
return Issues;
invalidInputException = new InvalidInputException(Issues)

 

But the issue is we are calling status, but instead need to check custom mandatory fields in the subtasks, if they are empty. the name or the key of the sub task should display in the validation. Is it possible?

 

The above code is also not working properly

 

you can also use this for reference (Using JWT)

https://community.atlassian.com/t5/Jira-questions/workflow-validator-validation-on-sub-tasks/qaq-p/1087989#M348907

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
June 1, 2019

Hi,

you probably want something like this:

def subtaskKeys = []
issue.subTaskObjects.each { subtask ->
if (!subtask.get("Field 1") || !subtask.get("Field 2"))
subtaskKeys += subtask.key
}
if (subtaskKeys)
return "Please update the following subtasks: " + subtaskKeys.join(", ")
return true

Suggest an answer

Log in or Sign up to answer