subtasks fields need to block parent transition

Scott Federman December 12, 2017

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
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 12, 2017

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")
}
}
}
Scott Federman December 12, 2017

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. 

Scott Federman December 12, 2017

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 like:log.info("...") 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>
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$4.call(Unknown Source)
 at Script8.run(Script8.groovy:14)
Tarun Sapra December 12, 2017

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"

Scott Federman December 12, 2017

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

Scott Federman December 12, 2017

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

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 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