Create Subtask Script not working Script workflow function : Create a sub-task.

Marcel J. Wüstner November 18, 2015

Hello, we've been using script-runner since quite a while but upgraded now to JIRA 7.0 and also script runner to 4.2. 

However our post-functions on transitions which creates subtasks are not working anymore.

I set the subtasks according to this:

Subtask will be created with issue type: Sub-task
Target Issue Type: Sub-Task
issue.summary = sourceIssue.summary + ' - Upload' 

everything else is empty. This setup worked before transitioning to JIRA 7.0 

 

In the log file i get this error message:

-------------------
2015-11-18 11:46:22,924 http-nio-8082-exec-6 ERROR mwuestner 706x58402x1 khtkk0 46.165.234.130,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2015-11-18 11:46:22,924 http-nio-8082-exec-6 ERROR mwuestner 706x58402x1 khtkk0 46.165.234.130,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: GME-5927, actionId: 571, file: null
com.atlassian.jira.exception.CreateException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@c6c3e62: root cause: java.lang.NullPointerException
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:748)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:636)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:761)
at com.atlassian.jira.issue.IssueManager$createIssueObject$0.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.utils.AbstractCloneIssue.doScript(AbstractCloneIssue.groovy:112)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CreateSubTask.super$2$doScript(CreateSubTask.groovy)
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CreateSubTask.doScript(CreateSubTask.groovy:123)
Caused by: com.atlassian.jira.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@c6c3e62: root cause: java.lang.NullPointerException
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:909)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:737)
... 6 more
Caused by: com.opensymphony.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@c6c3e62: root cause: java.lang.NullPointerException
at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1523)
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:879)
... 7 more
Caused by: java.lang.NullPointerException
at com.atlassian.jira.workflow.validator.AbstractPermissionValidator.hasUserPermission(AbstractPermissionValidator.java:49)
at com.atlassian.jira.workflow.validator.PermissionValidator.validate(PermissionValidator.java:46)
at com.atlassian.jira.workflow.SkippableValidator.validate(SkippableValidator.java:53)
at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1512)
... 10 more

 

For what i understand is, there is some issue with the permissions, however how do i need to update this?

 

9 answers

0 votes
Sarathi Chatterjee August 10, 2017

_

0 votes
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2015

Update your user name to match your user key. 

Find your user key: your-base-url/rest/api/2/myself

Edit your user name: Users -> User management -> Select the user and edit.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2015

Note: this is a bug, which will be fixed very soon.

Sarathi Chatterjee August 10, 2017

Has this been fixed ?

Thanks

Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 10, 2017

Hi Sarathi 

Yes it is fixed in version 4.2.0.2 

regards,

Thanos

Sarathi Chatterjee August 10, 2017

We get this on 4.3.18  

Installing 5.0.14 now 

Sarathi Chatterjee August 10, 2017

Error we get is 

 

017-08-10 15:57:58,084 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-08-10 15:57:58,085 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITSD-98, actionId: 1, file: <inline script>
com.atlassian.jira.exception.CreateException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@2232fbbc: root cause: java.lang.NullPointerException
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:588)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:494)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:599)
at com.atlassian.jira.issue.managers.RequestCachingIssueManager.createIssueObject(RequestCachingIssueManager.java:198)
at com.atlassian.jira.issue.IssueManager$createIssueObject$0.call(Unknown Source)
at Script211.createSubtask(Script211.groovy:64)
at Script211$_run_closure2.doCall(Script211.groovy:23)
at Script211.run(Script211.groovy:22)
Caused by: com.atlassian.jira.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@2232fbbc: root cause: java.lang.NullPointerException
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:760)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:580)
... 7 more
Caused by: com.opensymphony.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@2232fbbc: root cause: java.lang.NullPointerException
at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1477)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1167)
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606)
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:741)
... 8 more
Caused by: java.lang.NullPointerException
at com.atlassian.jira.workflow.validator.AbstractPermissionValidator.hasUserPermission(AbstractPermissionValidator.java:38)
at com.atlassian.jira.workflow.validator.PermissionValidator.validate(PermissionValidator.java:37)
at com.atlassian.jira.workflow.SkippableValidator.validate(SkippableValidator.java:45)
at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1466)
... 11 more

Cancel
Sarathi Chatterjee August 10, 2017

And the code in use on the POST Function on Create is 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def parentIssue = issue as MutableIssue

if (parentIssue.isSubTask()) {
//the issue in transition is a subtask therefore do nothing
return
}

def parentSummary = parentIssue.summary

// use http://docs.oracle.com/javase/tutorial/essential/regex/bounds.html because we want to match the exact word
if (parentSummary.matches(".*\\bOFFICE\\b.*")) {
['Create OFFICE Account', 'Create AD Account', 'Create Exchange Account'].eachWithIndex { it, idx ->
createSubtask(parentIssue, it, "Subtask $idx")
}
}
else if (parentSummary.matches(".*\\bOFFICE_2\\b.*")) {
['Create OFFICE_2 Account', 'Create AD_2 Account', 'Create Exchange Account_2'].eachWithIndex { it, idx ->
createSubtask(parentIssue, it, "Subtask $idx")
}
}
// follow the same pattern for other cases ....

/**
* Create an issue of issue type subtask, for the given parent issue and a text to concat in the parent issue's one
* in order to create the subtask's description.
* All the other required fields are inherited from the parent issue
* @param parentIssue The parent issue which is in transition
* @param description The text to concat to the parent's one in order to create the subtask's description
*/
def createSubtask (MutableIssue parentIssue, String description, String subtaskSummary) {
def subtaskDescription = "$description ${parentIssue.summary}"

// if there is a subtask with the exact description already then do nothing
if (subtaskAlreadyExist(parentIssue, subtaskDescription)) {
log.info "A subtask with description $subtaskDescription already exists, I will NOT create a new one"
return
}

def issueFactory = ComponentAccessor.getIssueFactory()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def subTaskManager = ComponentAccessor.getSubTaskManager()

def newSubTask = issueFactory.getIssue()

newSubTask.setSummary('HELLO')
newSubTask.setDescription(subtaskDescription)
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.projectObject)
newSubTask.setPriority(parentIssue.priority)
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
// Add any other fields you want for the newly created sub task see
// https://docs.atlassian.com/jira/7.3.5/com/atlassian/jira/issue/MutableIssue.html
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
log.info "Subtask with summary ${newSubTask.summary} created"
}

def subtaskAlreadyExist (MutableIssue parentIssue, String subtaskDescription) {
parentIssue.subTaskObjects?.find { it.description == subtaskDescription }
}
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 10, 2017

Can you try to replace the

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

with a user that has for sure Create Issue Permissions for this project ?
Something like

def user = ComponentAccessor.getUserManager().getUserByKey("admin")

let me know how this goes.

0 votes
Marcel J. Wüstner November 19, 2015

Additionally i have the following error when running the Scriptrunner Script registry

For the code:

issue.summary = sourceIssue.summary + ' - TEST'
[Static type checking] - The variable [sourceIssue] is undeclared. @ line 1, column 17.
[Static type checking] - Cannot find matching method java.lang.Object#plus(java.lang.String). Please check if the declared type is right and if the method exists.
Possible solutions: is(java.lang.Object), split(groovy.lang.Closure), use([Ljava.lang.Object;), use(java.lang.Class, groovy.lang.Closure), wait(), grep() @ line 1, column 37.

 

Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2015

This is a STC (static type checking) issue, but it doesn't make your action to fail.

Marcel J. Wüstner November 20, 2015

okay thank you. i am just trying to find anything which could give us an indication where teh problem is. Because of the failing script i have already half a project team not able to work in their used workflow which gives us a lot of overhead currently.

Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2015

Marcel could you please raise a support ticket here: https://productsupport.adaptavist.com/servicedesk/customer/portal/2, so we can continue the troubleshooting from there ? Thanks

0 votes
Marcel J. Wüstner November 19, 2015

I ran also the test-run from script runner built in scripts got the following errors, not sure if this helps

Run5
Failures8
Errortest script with workflow transitions(com.acme.scriptrunner.test.TestAddComponentLeadsAsWatchers)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@2065720
Errortest script with workflow transitions(com.acme.scriptrunner.test.TestAddComponentLeadsAsWatchers)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@51099a38
Errortest script with workflow transitions(com.acme.scriptrunner.test.TestAddComponentLeadsAsWatchers)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@26c0aa30
Errortest due date script field(com.acme.scriptrunner.test.TestVersionDueDateScriptedField)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@5e61946d
Errortest due date script field(com.acme.scriptrunner.test.TestVersionDueDateScriptedField)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@57d243ed
Errortest due date script field(com.acme.scriptrunner.test.TestVersionDueDateScriptedField)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@173162c4
Errortest due date script field(com.acme.scriptrunner.test.TestVersionDueDateScriptedField)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@21997723
Errortest due date script field(com.acme.scriptrunner.test.TestVersionDueDateScriptedField)
org.spockframework.runtime.ConditionNotSatisfiedError:
Condition not satisfied:

createValidationResult.isValid()
|                      |
|                      false
com.atlassian.jira.bc.issue.IssueService$CreateValidationResult@f1fc445
0 votes
Marcel J. Wüstner November 19, 2015

hi Thanos, i have admin-rights and i can also create tickets and subtickets manually but the workflow post function seems not to work.

0 votes
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 19, 2015

Hi Marcel, I tested in my local instance (JIRA7, SR-4.2), no problem appeared. As you mentioned there is something wrong with the user. Does this user has permission to create issues ?

Roy Chapman
Contributor
December 19, 2018

I had the same issue.  Turns out that the option to create sub task as user was failing.  This was a test project and the user selected had no permissions to create the sub task.

0 votes
Marcel J. Wüstner November 18, 2015

That's right, i am only using the built-in "Create subtask" script

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2015

Hi @Thanos Batagiannis [Adaptavist] , it's the built-in "Create subtask" script, he said he wasn't using any additional code.

0 votes
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2015

Hi Marcel, Would you like to post the script you use for your post function (a couple of API changes happened in JIRA7) ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events