I am trying to get a script that used to work on version 5.x on JIRA to run on a v7.1.6 version. The script was initially taken from the following webpage
https://answers.atlassian.com/questions/97963
Here is the script with modifications I am still having issues with line 13. Any help on the matter would be greatly appreciated.
import
com.atlassian.jira.ComponentManager
import
com.atlassian.jira.event.issue.AbstractIssueEventListener
import
com.atlassian.jira.event.issue.IssueEvent
import
com.atlassian.jira.issue.Issue
import
com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.component.ComponentAccessor
import
org.apache.log4j.Category
class
SubtaskCommentListener
extends
AbstractIssueEventListener {
Category log = Category.getInstance(SubtaskCommentListener.
class
)
CommentManager commentManager = ComponentManager.instance.commentManager
@Override
void
workflowEvent(IssueEvent event) {
// only one central way...
this.customEvent(event)
}
@Override
void
customEvent(IssueEvent event) {
// set explicit to debug
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug
"Event: \"${ComponentManager.instance.eventTypeManager.eventTypesMap[event.getEventTypeId()].name}\" fired for ${event.issue}"
// Here you should put any subtask based restrictions for this task like
// only for special subtask issue types or similar
Comment comment = event?.getComment()
if
(comment && event.issue.isSubTask()) {
log.debug
"New commment for subtask found."
Issue parent = event.issue.getParentObject()
// Here you should put any parent task based restrictions like
// only for special issue types or similar
commentManager.create(parent, comment.author, comment.updateAuthor, comment.body, comment.groupLevel, comment.roleLevelId, comment.created, comment.updated, true, true)
log.debug (
"Created comment on ${parent.key}"
)
}
}
}
Hi Pat,
You should create a new custom listener, associate it with the project/s you want and for event choose an Issue Commented. For inline script use
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.comments.Comment Issue subtask = event.issue Comment comment = event.comment def commentManager = ComponentAccessor.getCommentManager() if (subtask.isSubTask() && comment) { def parentIssue = subtask.getParentObject() def commentToParent = commentManager.create( parentIssue, //the parent issue to copy the comment comment.getAuthorApplicationUser(), //the author of the subtask's comment comment.getBody(), //the actual comment body comment.getGroupLevel(), // is the group name to limit comment visibility to, this must be a valid group name. comment.getRoleLevelId(), // is the id of the the ProjectRole to limit comment visibility to, this must reference a valid project role. false) //if true then an event of type EventType.ISSUE_COMMENTED_ID will be dispatched and any notifications listening for that event will be triggered. If false no event will be dispatched. log.info "Comment copied to parent issue ${parentIssue.getKey()}" }
The link to the code/class you pasted is for version <= JIRA6, the scirpt above is updated to fit JIRA7 API
Regards
Thanos
I'm getting an error with the "&&" in the IF line. Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This question was converted over from the previous "Answers" site, which messed up some of the formatting in places. & is a reformatted &, so just swap them to that in your script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now I'm getting an error with:
def commentToParent = commentManager.create(
Cannot find matching method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Best guess is that you're on a different version of Jira to the one the script works for. You'll need to use the api docs for the current version to work out what methods to use
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
Although there was an error the script still appears to work for adding comments editing and deleting comments.
Thank you for your quick response to my issue.
Pat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
Thank you for the new code.
I tried your new code out on a system and although the code itself comes up with no errors I do get an error when it runs through the code. It is still pointing at the same line. The log information on this is as follows:
Time (on server): Fri Jul 08 2016 09:20:20 GMT-0700 (Pacific Daylight Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2016-07-08 09:20:20,565 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2016-07-08 09:20:20,581 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script51.groovy: 13: unable to resolve class CommentManager @ line 13, column 5. CommentManager commentManager = ComponentManager.instance.commentManager ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos,
I tried your new code out on a system and although the code itself comes up with no errors I do get an error when it runs through the code. It is still pointing at the same line. The log information on this is as follows:
Time (on server): Fri Jul 08 2016 09:20:20 GMT-0700 (Pacific Daylight Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2016-07-08 09:20:20,565 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2016-07-08 09:20:20,581 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script51.groovy: 13: unable to resolve class CommentManager @ line 13, column 5. CommentManager commentManager = ComponentManager.instance.commentManager ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry about that. Thought I had included the error. I think cutting and pasting into the webpage screwed up the lines for me.
This is the line it errors out on
CommentManager commentManager = ComponentManager.instance.commentManager
Unable to resolve class CommentManager @line13 column 5
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Which is line 13 (empty by my count) and what is the error?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.