subtasks fields need to block parent transition

using scriptrunner, could someone share with me how i would create a validator where i have three custom fields in a subtask (unit price, quote number, part number) that must be filled out in order to transition the parent? And if not will return a message that says " unit price, quote number, part number on each line item must be entered to proceed"

1 answer

1 accepted

1 vote
Accepted answer

This should do the trick

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.opensymphony.workflow.InvalidInputException;

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def unit_price = customFieldManager.getCustomFieldObjectByName('Unit Price');
def quote_number = customFieldManager.getCustomFieldObjectByName('Quote number');
def part_number = customFieldManager.getCustomFieldObjectByName('Part Number');

def subTasks = issue.getSubTaskObjects();
if(subTasks) {
subTasks = (Collection<Issue>)subTasks;
for(Issue subTask : subTasks) {
if(!(subTask.getCustomFieldValue(unit_price) && subTask.getCustomFieldValue(quote_number) && subTask.getCustomFieldValue(part_number))) {
throw new InvalidInputException("Unit price, part number, and quote number are required on subtasks")

Thank you Tarun. It worked as long as those fields were filled out on one of the sub-tasks. However, i need to ensure it validates those fields are inputted on all subtasks. 

it did throw this error

Time (on server): Tue Dec 12 2017 10:23:20 GMT-0600 (Central Standard Time)

The following log information was produced by this execution. Use statements"...") to record logging information.

2017-12-12 09:23:20,193 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-12-12 09:23:20,194 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: OPS-577, actionId: 31, file: <inline script>
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$ Source)

Did you put proper custom field name in the above code?

Like in

customFieldManager.getCustomFieldObjectByName("here you have to enter the exact name of the custom field"

it looked like a case sensitive issue. thank you so much for that.

do you have time for one more? its a bit more complex. :)

Tarun Sapra Community Champion Dec 13, 2017

Hi @Scott Federman, sure tell me, but I would suggest to create another question and share the link here as it's always better not to mix two questions.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,240 views 5 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you