Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner Clone project on transition - problem with issues

Wojtek Miecznikowski January 21, 2019



I trying prepare self service to creating JIRA projects. Now in JIRA working project clone, but just without issues - everythink looks good, but i last case i need copy Issues from source project. I trying a lot things with code like below :

package examples
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.Issue
//import com.onresolve.jira.groovy.user.FormField
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.onresolve.jira.groovy.MyCopyProjectScript")
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def destProjetKey = 'ASAP'
def srcProjectKey = 'SPP'
def destProjectName = 'ASAP'

log.debug("Source Project Name: " + srcProjectKey)

Thread executorThread = new Thread(new Runnable() {
void run() {
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : srcProjectKey,
(CopyProject.FIELD_TARGET_PROJECT) : destProjetKey,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : destProjectName,
(CopyProject.FIELD_COPY_VERSIONS) : true,
(CopyProject.FIELD_COPY_COMPONENTS) : true,
(CopyProject.FIELD_COPY_ISSUES) : true,
//(CopyProject.FIELD_COPY_GREENHOPPER) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
(CopyProject.FIELD_ORDER_BY) : "Rank",

def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
log.warn("Couldn't create project: " + errorCollection)
else {
def util = ComponentAccessor.getUserUtil()
def adminsGroup = ComponentAccessor.getGroupManager().getGroup("jira-administrators")
assert adminsGroup // must have jira-administrators group defined
def admins = util.getAllUsersInGroups([adminsGroup])
assert admins // must have at least one admin

def executingAdmin = ComponentAccessor.getUserManager().getUserByName(admins.first().name)
log.debug("Executing Admin: " + executingAdmin.getName())


and without result. Code working fine in "Run Script" from Add-ons level, but from transition leve Issues is not able to copy (with error NullPointerException. In atlassian-jira I receiving:

2019-01-21 11:36:23,529 ajp-nio-8009-exec-2 ERROR 696x12002x1 1kbyjsn /secure/WorkflowUIDispatcher.jspa [c.o.s.c.jira.utils.AbstractCloneIssue] Failed to create issue
com.atlassian.jira.exception.CreateException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Expected one match for [Expr::id::=::15123] but found 0: []


2019-01-21 11:36:23,544 ajp-nio-8009-exec-2 ERROR  696x12002x1 1kbyjsn /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: SS-105, actionId: 111, file: <inline script>


I tried:

- remove any validators

- every place in post function 

- use 2 type of post funcions: JMWE groovy script and scriptu runner script

- allow everything for my user in permission scheme

- change executingadmin

but still everything working fine from Add-ons level, but not working from transition level.


 JIRA 7.10.2

ScriptRunner 5.4.47



Anyone have any idea? I will be grateful for any advise.

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Matthew Clark
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.
February 1, 2019

Hi Wojciech

On the last line, you are calling the run method on the "executorThread" class you instantiated which does not actually create a new thread. It will just call the run method for the current thread.

If the current thread has already been started or stopped then you will get a IllegalStateException, like the one you have posted. You need to call the start method to create a new thread where your defined run method will execute.

I had a similar issue before when a user needed to clone a template project as a post function based on the value of some fields in the issue that they were transitioning. I will link it here as it may help you get your script working.

Wojtek Miecznikowski February 20, 2019

Hi Matthew,

Thanks for answer! You have right. I got answer from adaptavista support and was this same :).

Wojciech Miecznikowski

Like Matthew Clark likes this
Andreas November 8, 2019

Hi @Matthew Clark 

In the linked script you wrote a comment that it does not copy existing issues. We have the current version ( and the same errors in the log as described by @Wojtek Miecznikowski.

We can copy the project but without issues. Could you already find a solution for that?

Best regards

Matthew Clark
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 8, 2019

This only impacts Jira 8

Our CopyProject class has a slight difference in the Jira 8 version of scriptrunner. It still works in places where we call it internally like the built-in scripts, however, this change had an unexpected impact on users who are using our class by manually calling it in their scripts within POST functions.

The problem occurs when you try to run the CopyProject methods inside a thread within a POST function.
Some of the more complex CopyProject methods such as Copying Issues must be run inside a Thread when used as a POST function so unfortunately you cannot just take it out of the Thread and use it in a Post Function.

I created a bug ticket for this here SRJIRA-3793

You can still use our CopyProject class within a Listener as you do not need to run the CopyProject methods inside a Thread within a Listener.

Andreas November 12, 2019

Thank you for your fast reply. Unfortunately I don't really understand the thread problem :-) 

We are using a listener to copy the project but with an own event which is called by a postfunction. Should it copy the issues there or not? Do you know clean a workaround to copy the issues from the template after the project was created?

Matthew Clark
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 12, 2019

The listener should be able to copy issues.

I would need to see any atlassian-jira.log errors and the script to tell you why it might not be doing this if it is failing to.

I have seen other users trying this with custom events and it also failed. This is usually because the custom event object did not contain the correct properties required by their script.

Try your tests with a standard Jira Issue event like the Issue Updated or issue Created events.

I am sure you know this but make sure you do this on a test box. Playing around with issue updated/issue created events should always be done in a test environment to avoid spamming your users or accidentally creating loops.

Andreas November 12, 2019

You are right, after further tests i found a different error in the log. I have copied exactly your script and created a new listener with it. The error is the same when I use a custom event as when using the issue updated event. Seems like the script cannot find the correct table in the tries to insert an entry into "NULL":


2019-11-12 21:34:27,788 JIRA-INFORM-Thread-0 ERROR ag 1294x291x1 nmlp4q /secure/QuickCreateIssue.jspa [c.a.j.p.inform.performance.MeasurementWorkerFactory] Exception occured
com.querydsl.core.QueryException: Caught SQLServerException for insert into "null"."AO_733371_EVENT" ("CREATED", "EVENT_TYPE", "USER_KEY", "ACTION", "ACTION_ID", "EVENT_BUNDLE_ID") values (?, ?, ?, ?, ?, ?)
at com.querydsl.sql.DefaultSQLExceptionTranslator.translate(
at com.querydsl.sql.Configuration.translate(
at com.querydsl.sql.dml.SQLInsertClause.executeWithKeys(
at com.querydsl.sql.dml.SQLInsertClause.executeWithKey(
at com.querydsl.sql.dml.SQLInsertClause.executeWithKey(
at com.atlassian.pocketknife.internal.querydsl.DatabaseAccessorImpl.lambda$execute$0(
at com.atlassian.sal.core.rdbms.DefaultTransactionalExecutor.executeInternal(
at com.atlassian.sal.core.rdbms.DefaultTransactionalExecutor.lambda$execute$0(
at com.atlassian.jira.database.DatabaseAccessorImpl.runInManagedTransaction(
... 3 filtered
at java.lang.reflect.Method.invoke(
at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(
at com.sun.proxy.$Proxy429.runInManagedTransaction(Unknown Source)
... 3 filtered
at java.lang.reflect.Method.invoke(
at com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(
at com.sun.proxy.$Proxy429.runInManagedTransaction(Unknown Source)
at com.atlassian.sal.jira.rdbms.JiraHostConnectionAccessor.runInStartedOrExistingTransaction(
at com.atlassian.sal.jira.rdbms.JiraHostConnectionAccessor.execute(
at com.atlassian.sal.core.rdbms.DefaultTransactionalExecutor.execute(
at com.atlassian.pocketknife.internal.querydsl.DatabaseAccessorImpl.execute(
at com.atlassian.pocketknife.internal.querydsl.DatabaseAccessorImpl.runInTransaction(
at com.atlassian.jira.plugins.inform.performance.MeasurementWorkerFactory$1.measure(
at java.util.Spliterators$ArraySpliterator.forEachRemaining(
at com.atlassian.jira.plugins.inform.performance.MeasurementWorkerFactory$1.lambda$measure$0(
at com.atlassian.jira.plugins.inform.performance.MeasurementWorkerFactory$1.measure(
at com.atlassian.jira.plugins.inform.performance.MeasurementWorkerFactory$1.measure(
at java.util.concurrent.Executors$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: Invalid object name 'null.AO_733371_EVENT'.
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(
at com.atlassian.jira.ofbiz.sql.PreparedStatementWrapper.executeUpdate(
at com.atlassian.jira.diagnostic.connection.DiagnosticPreparedStatement.lambda$executeUpdate$7(
at com.atlassian.diagnostics.internal.platform.monitor.db.DefaultDatabaseDiagnosticsCollector.recordExecutionTime(
at com.atlassian.jira.diagnostic.connection.DatabaseDiagnosticsCollectorDelegate.recordExecutionTime(
at com.atlassian.jira.diagnostic.connection.DiagnosticPreparedStatement.executeUpdate(
at com.querydsl.sql.dml.SQLInsertClause.executeWithKeys(
... 56 more


We have a similar issue if we enable the E-Mail batching feature:

Matthew Clark
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 13, 2019

I am not sure if this is a Scriptrunner issue. It looks like your server is having trouble finding the DATABASE name. (sometimes named jiradb)

Caught SQLServerException for insert into "null"."AO_733371_EVENT" 

You get the same type of "null" error in your batch email functionality issue you linked

Caused by: Invalid object name 'null.AO_0A5972_NOTIFICATION_SETTING'

I believe the "null" part should be the name of the database and it is strange that it cannot find it. I would need to research more but it might be a database permission problem. Can you access the database as the user that the Jira process runs as and check what databases you can see and if they contain the above table names?

Andreas November 19, 2019

With the help of Atlassian Support we were able to solve this issue. The problem was the missing database scheme in dbconfig.xml. The SQL exceptions do not appear any more.

Now I tried again to create a new project including issues.
If I try to use your script again including creating a new thread it still does not create any issue. This time there is no error in the log anymore. I tried to add some log messages into the script - from the line with the command "copyProject.doScript(inputs)" no further log messages are visible in the log file. Do you have an idea why this occurs?

Matthew Clark
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.
December 22, 2019

Apologies for the delay it has been very busy lately.

The problem you describe above is what this bug I linked earlier is for SRJIRA-3793

I believe we need to alter the CopyProject class in order for users to be able to manually call it from a post-function script so the bug will need to be fixed before it can be used in a POST function to copy Projects.

You should be able to use our CopyProject class with a listener instead as long as you remove the parts that put it in a Thread.

Make sure your listener script does not listen for all projects as that could potentially cause a loop of project creation.

Racha Touzi[Spectrum Groupe] February 4, 2020

Hello matthew

I tried your suggested solution , i used a listener to copy project with issues instead of a Post Function . But it didn't work. The issues are not copied.

Is there another solution please and when you will fix this problem for JIRA 8 ?

Thank you in advance for your answer.

Best Regards

0 votes
Madhura sarwade February 19, 2019

Issue type scheme is not being copied from source project. It takes default issue type scheme.

AUG Leaders

Atlassian Community Events