Scriptrunner Create Sub-task not working properly

I *think* I may have discovered a scenario in which the current "Create a sub-task" listener does not work.

This is my setup:

In my workflow, as a validator for create issues I have the following piece of code:

if (issue.getIssueTypeObject().isSubTask()) {
	if (issue.getParentObject() == 'Sticky Task' || issue.getParentObject() == 'Dreams & Ideas') {
		return false;}
        else {
        	return true;
else {
return true;

The above code is tried and true: It does not allow Sub-task issue types for those two issue types mentioned.

Now, I am attempting to create a listener that, whenever an issue is updated and certain criteria is met, a set of sub-tasks are created. However, the sub-tasks are not creating. Looking at the logs, I am seeing that the reason why the sub-tasks are not being created is because of my validator above (error description below).

Any thoughts why the validator is working properly through the interface, but it's preventing a script listener to create a Sub-task properly?

Thank you for your help!

2014-03-14 17:38:06,480 http-bio-8080-exec-557 ERROR jrivero 1058x95924x1 1bs1w89 /secure/QuickEditIssue.jspa [atlassian.event.internal.AsynchronousAbleEventDispatcher] There was an exception thrown trying to dispatch event 'com.atlassian.jira.event.issue.IssueEvent@6b08461[issue=AS-2527,comment=<null>,worklog=<null>,changelog=[GenericEntity:ChangeGroup][id,88908][author,jrivero][created,2014-03-14 17:38:06.402][issue,24508],eventTypeId=2,sendMail=true,params={eventsource=action, baseurl=http://jira:8080},subtasksUpdated=true]' from the invoker 'SingleParameterMethodListenerInvoker{method=public void com.onresolve.jira.groovy.listener.ScriptRunnerUberListener.workflowEvent(com.atlassian.jira.event.issue.IssueEvent), listener=com.onresolve.jira.groovy.listener.ScriptRunnerUberListener@209a531c}'.
java.lang.RuntimeException: Error occurred while creating issue through workflow: You may not create a Sub-task for the parent issue type.
	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1.execute(
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(
	at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(
	at com.atlassian.event.internal.EventPublisherImpl.publish(
	at com.atlassian.multitenant.event.DefaultPeeringEventPublisherManager.publish(
	at com.atlassian.multitenant.event.PeeringEventPublisher.publish(
	at com.atlassian.jira.event.issue.DefaultIssueEventManager.publishEvent(
	at com.atlassian.jira.event.issue.DefaultIssueEventManager.dispatchEvent(
	at com.atlassian.jira.issue.util.DefaultIssueUpdater.doUpdate(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.doUpdate(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(
	at com.atlassian.jira.bc.issue.DefaultIssueService.update(
	at com.atlassian.jira.bc.issue.DefaultIssueService.update(  <+2> (
	at java.lang.reflect.Method.invoke(
	at com.atlassian.multitenant.impl.MultiTenantComponentFactoryImpl$AbstractMultiTenantAwareInvocationHandler.invokeInternal(
	at com.atlassian.multitenant.impl.MultiTenantComponentFactoryImpl$MultiTenantAwareInvocationHandler.invoke(
	at $Proxy396.update(Unknown Source)  <+2> (
	at java.lang.reflect.Method.invoke(
	at com.atlassian.plugin.osgi.hostcomponents.impl.DefaultComponentRegistrar$ContextClassLoaderSettingInvocationHandler.invoke(
	at $Proxy396.update(Unknown Source)  <+2> (
	at java.lang.reflect.Method.invoke(
	at com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(
	at $Proxy396.update(Unknown Source)
	at com.atlassian.jira.quickedit.action.QuickEditIssue.doExecute(  <+1> (
	at com.atlassian.jira.action.JiraActionSupport.execute(  <+7> ( ( ( ( ( ( (
	at javax.servlet.http.HttpServlet.service(  <+14> ( ( ( ( ( ( ( ( ( ( ( ( ( (
	at com.atlassian.labs.botkiller.BotKillerFilter.doFilter(  <+3> ( ( (
	at com.atlassian.jira.tzdetect.IncludeResourcesFilter.doFilter(  <+3> ( ( (
	at com.atlassian.jira.baseurl.IncludeResourcesFilter.doFilter(  <+8> ( ( ( ( ( ( ( (
	at com.atlassian.mywork.client.filter.ServingRequestsFilter.doFilter(  <+20> ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (
	at com.atlassian.labs.remoteapps.modules.permissions.ApiScopingFilter.doFilter(  <+32> ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (
	at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(
	at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(
	at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(  <+9> ( ( ( ( ( ( ( ( (
	at com.atlassian.labs.remoteapps.modules.oauth.OAuth2LOFilter.doFilter(  <+3> ( ( (
	at com.atlassian.labs.remoteapps.util.http.bigpipe.RequestIdSettingFilter.doFilter(  <+43> ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
	at java.util.concurrent.ThreadPoolExecutor$
Caused by: com.atlassian.jira.exception.CreateException: Error occurred while creating issue through workflow: You may not create a Sub-task for the parent issue type.
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(
	at com.atlassian.jira.issue.IssueManager$ Source)
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.AbstractCloneIssue.doScript(AbstractCloneIssue.groovy:80)  <+3> ( (
	at java.lang.reflect.Method.invoke(
	at org.codehaus.groovy.reflection.CachedMethod.invoke(
	at groovy.lang.MetaMethod.doMethodInvoke(
	at groovy.lang.MetaClassImpl.invokeMethod(
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(
	at com.onresolve.jira.groovy.canned.workflow.postfunctions.CreateSubTask.doScript(CreateSubTask.groovy:118)
	at com.onresolve.jira.groovy.canned.CannedScript$ Source)
	at com.onresolve.jira.groovy.CannedScriptRunner.runCannedScript(CannedScriptRunner.groovy:63)
	at  <+3> ( (
	at java.lang.reflect.Method.invoke(
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(
	at com.onresolve.jira.groovy.listener.ScriptRunnerUberListener$_workflowEvent_closure1.doCall(ScriptRunnerUberListener.groovy:48)  <+2> (
	at java.lang.reflect.Method.invoke(
	at org.codehaus.groovy.reflection.CachedMethod.invoke(
	at groovy.lang.MetaMethod.doMethodInvoke(
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(
	at groovy.lang.MetaClassImpl.invokeMethod(
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(
	at org.codehaus.groovy.runtime.dgm$149.invoke(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(
	at com.onresolve.jira.groovy.listener.ScriptRunnerUberListener.workflowEvent(ScriptRunnerUberListener.groovy:35)  <+2> (
	at java.lang.reflect.Method.invoke(
	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(
	... 189 more
Caused by: [InvalidInputException: [Error map: [{}]] [Error list: [[You may not create a Sub-task for the parent issue type.]]]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
	at java.lang.reflect.Constructor.newInstance(
	at org.codehaus.groovy.reflection.CachedConstructor.invoke(
	at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(
	at com.onresolve.jira.groovy.canned.workflow.validators.SimpleScriptedValidator.doScript(SimpleScriptedValidator.groovy:66)
	at com.onresolve.jira.groovy.canned.CannedScript$ Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at com.onresolve.jira.groovy.canned.CannedScript$ Source)
	at com.onresolve.jira.groovy.CannedScriptRunner.runCannedScript(CannedScriptRunner.groovy:63)
	at com.onresolve.jira.groovy.GroovyValidator.validate(
	at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(
	at com.opensymphony.workflow.AbstractWorkflow.initialize(
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(
	... 234 more

9 answers

Which version of JIRA are you running ?

Does the same error appears if you remove the validator ?

Thank you for getting back to me so quickly.

I tried removing the validator, and the Scriptrunner listener *worked* (created the subtask successfully). However, I have to put that validator back in because I need it in place. Any thoughts?

I am running JIRA v5.2.7.

Are you sure you're getting the "right" issue when you call issue.getParentObject()?

Can you add a println and check which issue is returned by issue.getParentObject() when the error appears ?

I believe so. I mean I have tested this through the interface for every possible scenario and the validator works correctly.

But you bring up a good point... perhaps when the validator is called through the Script Listener code, it does *not* return the right parent object. Is there a different more accurate way to get the parent object for both scenarios? Maybe when I'm in the listener, the issue is not really the sub-task yet or something, or it gets created differently? That is the only possible explanation.

At any rate, I could put that println to verify, but where should I put it and would it come out through the logs?

Hi Jorge, you should probably initialize and use the logger for this LOG.warn(...) it is a good way to debug this functionality.

I think it will come up in the logs, but I'm not 100% sure. Just put it as a first line in the validator script



What type of validator is it... the one called "simple scripted validator"?

println typically will not come up in atlassian-jira.log, but "log.warn(...)" will.

Thank you all for the help. Here's the the log.warn(...) added at the beginning of the validator. The validator remains the same as the OP.


Observation - Adding a log.warn to the beginning of the validator caused it to return false regardless of what came next. I had to do this quickly to capture the error, but then quickly removed it from the validator because as it stands, it works fine for adding a sub-task through the interface.

Results - Here are the two scenarios for adding a sub-task, and respective results:

1) When adding a sub-task through the interface manually

  • log.warn(issue.getKey()) = was EMPTY
  • log.warn(issue.getParentObject().getKey()) = was the PARENT KEY
  • END RESULT = Sub-task was successfully added (according to Validator criteria)

2) When attemting to add a sub-task through the Scriptrunner listener

  • log.warn(issue.getKey()) = was EMPTY
  • log.warn(issue.getParentObject().getKey()) = was ERROR: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getKey() on null object
  • END RESULT = Sub-task was not added, and gave me the same error as the OP.

I think the problem is that issue is something different during #1 and something else during #2. Jamie, you would know best, but looking at the script source of the "Create a sub-task" listener, on line 120-126, I see this

Issue newIssue = params['newIssue'] as Issue

        def subTaskManager = componentManager.getSubTaskManager()

        // get a fresh copy of the issue, otherwise the old version gets indexed by the createSubTaskIssueLink method
        // issue = ComponentAccessor.getIssueManager().getIssueObject(
        subTaskManager.createSubTaskIssueLink(issue, newIssue, user)

Would that have something to do with the error and how issue is instantiated and handled in the 2 scenarios above?

Thanks for any guidance you may be able to provide.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

441 views 8 26
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