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"
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it looked like a case sensitive issue. thank you so much for that.
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.
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.
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.