Create a sub-task and copy the parten comment

Xavier Torres
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 26, 2018

Hi everyone,

As for the enviroment i'm using Jira Software and the only plugin im using is ScriptRunner.

My aim is to program a post-fucntion such as in the moment i transicionate an issue to "in progress" a sub-task with the same fields is created. Also, during the transition I pick up a comment that has to be in both Task and Sub-Task.

I'm using one of the build-in scripts of ScriptRunner "Create a sub-task"

Also I added this code

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.*

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment(sourceIssue)
commentManager.create(issue,currentUser,comment.getBody(),true)


But all I get is this message

org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.

And inside the log this one :

2018-09-26 16:18:21,949 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2018-09-26 16:18:21,950 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: COM-56, actionId: 11, file: null
java.lang.IllegalArgumentException: eq(null) is not allowed. Use isNull() instead
	at com.querydsl.core.types.dsl.SimpleExpression.eq(SimpleExpression.java:127)
	at com.atlassian.jira.issue.comments.DefaultCommentManager.lambda$create$0(DefaultCommentManager.java:263)
	at com.atlassian.jira.database.DefaultQueryDslAccessor.lambda$execute$1(DefaultQueryDslAccessor.java:74)
	at com.atlassian.jira.database.DatabaseAccessorImpl.runInTransaction(DatabaseAccessorImpl.java:110)
	at com.atlassian.jira.database.DefaultQueryDslAccessor.execute(DefaultQueryDslAccessor.java:73)
	at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:258)
	at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:227)
	at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:217)
	at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:201)
	at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:190)
	at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:179)
	at com.atlassian.jira.issue.comments.CommentManager$create$3.call(Unknown Source)
	at Script5.run(Script5.groovy:12)

 
I figured out the proble is with the "issue" variable used on commentManager.create, but I don't understand why?

Any Idea?

Thanks :D

1 answer

0 votes
Christoph Schötz
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 25, 2019

Hi Xavier,

I was not able to fix this quickly but what I did is writing the comment to the description of the created sub-task and copying it in its create postfunction to a new comment using JSU (of course after the create issue postfunction). What I could imagine here is that the subtask issue is not fully created at the time these additional actions are executed and the commentManager can't add comments to a yet uncreated issue...

Best regards

Christoph

Suggest an answer

Log in or Sign up to answer