I am trying to trigger a custom event from my groovy script.
IssueEventManager.dispatchEvent(new Long(10001),x,ManagerFactory.getWorkflowManager().getCaller(transientVars),true);
I am getting this error
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.workflow.OSWorkflowManager.getCaller() is applicable for argument types: (java.util.HashMap) values: [[createdStep:SimpleStep@11[owner=, actionId=0, status=Open], ...]]
Can anyone provide me a working snippet of how to trigger a custom event programatically
This depends on your JIRA version and where you trigger the script. I suspect it's in a workflow postfunction, where you could use currentUser for the user part of dispatchEvent().
I got it to work with this snippet
HashMap params = new HashMap(); params.put( "baseurl" , ManagerFactory.getApplicationProperties().getString(APKeys.JIRA_BASEURL)); //prevent a mail from being generated params.put( "dispatchEvent" , new Boolean( false )); EventType event = ComponentManager.getInstance().getEventTypeManager().getEventType( 10001); IssueEvent issueEvent = new IssueEvent( issue, params, remoteUser, event.getId() ); IssueEventDispatcher.dispatchEvent( issueEvent ); |
I am not being able to get an outgoing mail when I fire the event . I have created a custom event and have configured it in my default notification scheme . I am using that id over here in the snippet(10001). Is there any other configuraton I need to send the email
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is it a listener you're runing? In this case you could use event.user otherwise your approach should work. Maybe you could log which user you get from the authenticationContext, sometimes this is null.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add
import com.atlassian.jira.component.ComponentAccessor def issueEventManager = ComponentAccessor.getIssueEventManager()
to your code to import the ComponentAccessor and use this class to get the issueEventManager.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you
now i get the following
image2016-6-13 15:1:16.png
sorry, i'm not really into scripting
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you post the complete code you're using? The message indicates you may be using the wrong parameters.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
here the original code.
It syncs comments between issues in two projects. What it won't do, is to trigger a issuecommented Event in the destination issue. This is what i'm trying to add.
import java.util.ArrayList; import java.util.List; import org.apache.log4j.Category; import com.atlassian.jira.component.ComponentAccessor; 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.IssueManager; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.comments.Comment; import com.atlassian.jira.issue.comments.CommentManager; import com.atlassian.jira.issue.comments.MutableComment; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.link.IssueLinkManager; Category log = Category.getInstance("SyncComments"); IssueManager issueManager = ComponentAccessor.getIssueManager(); log.info("SyncComments started"); Comment c = event.getComment(); if (c == null) return; List<Issue> linkedIssues = new ArrayList<Issue>(); IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager(); List<IssueLink> links = issueLinkManager.getInwardLinks(event.getIssue().getId()); if (links != null && links.size() > 0) for (IssueLink issueLink : links) { switch (Integer.parseInt(String.valueOf(issueLink.getIssueLinkType().getId()))) { case 10801: linkedIssues.add(issueManager.getIssueObject(issueLink.getSourceId())); break; } } links = issueLinkManager.getOutwardLinks(event.getIssue().getId()); if (links != null && links.size() > 0) for (IssueLink issueLink : links) { int linkid = Integer.parseInt(String.valueOf(issueLink.getIssueLinkType().getId())); log.info("linkid: "+linkid); switch (linkid) { case 10801: linkedIssues.add(issueManager.getIssueObject(issueLink.getDestinationId())); break; } } log.info("linkedIssues: "+linkedIssues.size()); for (Issue issueDest : linkedIssues) { MutableIssue issueDestination = issueManager.getIssueObject(issueDest.getId()); if (issueDestination != null) { CommentManager commentManager = ComponentAccessor.getCommentManager(); Comment destinationComment = null; List<Comment> comments = commentManager.getComments(issueDestination); for (Comment comment : comments) { if (comment.getAuthorApplicationUser().equals(c.getAuthorApplicationUser()) && comment.getCreated().equals(c.getCreated())) destinationComment = comment; } Comment triggerComment = event.getComment(); if (destinationComment != null) { // comment is still there and has to be updated MutableComment destinationMutableComment = commentManager .getMutableComment(destinationComment.getId()); destinationMutableComment.setBody(triggerComment.getBody()); destinationMutableComment.setGroupLevel(triggerComment.getGroupLevel()); destinationMutableComment.setRoleLevelId(triggerComment.getRoleLevelId()); destinationMutableComment.setUpdateAuthor(triggerComment.getUpdateAuthorApplicationUser()); destinationMutableComment.setUpdated(triggerComment.getUpdated()); commentManager.update(destinationMutableComment, false); log.info("SyncComment edited a comment with id " + destinationMutableComment.getId()+ " at the issue with key " + issueDestination.getKey()); } else { // Comment has to be created Comment comment = commentManager.create(issueDestination, triggerComment.getAuthorApplicationUser(), triggerComment.getUpdateAuthorApplicationUser(), triggerComment.getBody(), triggerComment.getGroupLevel(), triggerComment.getRoleLevelId(), triggerComment.getCreated(), triggerComment.getUpdated(), false); log.info("SyncComment created a comment with id " + comment.getId() + " at the issue with key "+ issueDestination.getKey()); } } } log.info("SyncComment finished");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this
import com.atlassian.jira.event.type.EventType def issueEventManager = ComponentAccessor.getIssueEventManager() issueEventManager.dispatchEvent(EventType.ISSUE_COMMENTED_ID, issueDestination, c.authorApplicationUser.directoryUser, true) issueEventManager.dispatchEvent(EventType.ISSUE_COMMENT_EDITED_ID, issueDestination, c.updateAuthorApplicationUser.directoryUser, true)
The first dispatchEvent is for the else{} part, the second for the if{} part.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Forget my comment... just replace the last parameter false of commentManager.update() and commentManager.create() with true and the correct event should be triggered.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
great! works perfectly
thank you very much
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.