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

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

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

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 ?

This widget could not be displayed.

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

This widget could not be displayed.

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
This widget could not be displayed.

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.

 

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

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.

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

This widget could not be displayed.

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.

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

Has this been fixed ?

Thanks

Hi Sarathi 

Yes it is fixed in version 4.2.0.2 

regards,

Thanos

We get this on 4.3.18  

Installing 5.0.14 now 

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

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 }
}

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.

This widget could not be displayed.

_

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

536 views 3 19
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