Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner REST Endpoint: Can't trigger events

Aleksa Svitlica January 22, 2020

I have a ScriptRunner Rest Endpoint which upon receiving a response will add a comment and transition an issue. I would expect these actions to generate events like Issue Commented or Generic Event which should be picked up by the ScriptRunner Listeners. When I perform the same actions in the ScriptRunner Console I can see that my listeners do in fact run as expected. However nothing I do in the REST Endpoint can cause a Listener to run. Is there something I am missing or another way to accomplish what I need?

 

Here is an example function I used to try to generate an event, it works in Script Console but doesn't appear to in the REST Endpoint.


def dispatchGenericEvent(MutableIssue issue){    

 IssueEventManager issueEventManager = ComponentAccessor.getIssueEventManager()    IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactoryComponentAccessor.getComponent(IssueEventBundleFactory.class)
    IssueEventBundle eventBundle = issueEventFactory.wrapInBundle(new IssueEvent(issue, null, botUser, EventType.ISSUE_GENERICEVENT_ID, true))    issueEventManager.dispatchEvent(eventBundle)

}


MutableIssue issue = issueManager.getIssueObject("HELPDESK-20092")
dispatchGenericEvent(issue)

2 answers

1 accepted

1 vote
Answer accepted
Aleksa Svitlica January 29, 2020

For anyone that runs into the same problem I never did figure out how to generate events directly from the ScriptRunner REST Endpoint.

However since my use case involved performing a transition on an issue I could add another post function to run a custom script which generated the event. Which is strange that it works because the post function immediately before my custom script is supposed to throw an event anyway...

0 votes
saravp2020 March 7, 2023

Hi,

By default the REST Endpoint not invoking the listener, but if you are using scriptrunner code to comment/update an issue from REST Endpoint, then can make use of the out of the box method param available while using API IssueManager->updateIssue. 

issueManager.updateIssue(ApplicationUser user, MutableIssue issue, EventDispatchOption eventDispatchOption, boolean sendMail)

In above piece of code snippet, EventDispatchOption can be set to an event to be dispatched and this will in turn invoke the Listener event.

Example below:
IssueManager issueManager = ComponentAccessor.getIssueManager();
issueManager.updateIssue(applicationUser, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false);

In above example, when there is an issue update is happening within REST Endpoint, the 'EventDispatchOption.ISSUE_UPDATED' will help to invoke the listener for issue update, so should make sure to have 'Issue Updated' or 'All Issue Events' listener exists in first place to capture and test it, this one worked for me.

Although I have not tried, for original query in this page where issue comment wanted to be captured, I believe similar 'EventDispatch' option can be used on Comment as well using below code snippet, hope 'Issue Commented' listener event will be triggered, so make sure to have 'Issue Commented' or 'All Issue Events' listener created to catch this event in first place:

CommentManager.create(Issue issue, ApplicationUser author, ApplicationUser updateAuthor, String body, String groupLevel, Long roleLevelId, Date created, Date updated, boolean dispatchEvent)

Suggest an answer

Log in or Sign up to answer