Hello people
I've written a script (dialog through attachments are sent to another system) with Script Runner REST Endpoints on Jira Server. It works fine when I call it through Fragments -> Custom web item. I call the dialog with a link like this: /rest/scriptrunner/latest/custom/showDialog?issueKey=${issue.key}
But now, what I'm trying to do is calling the dialog when an attachment is added. So I was trying to add a Listener -> Custom listener.
1. There is no "Attachment added" event. I chose "Issue created" & "Issue updated".
2. Unfortunately, I couldn't select an issue type. The event should only be fired with a certain issue type.
3. How can I check now, if an attachment got added?
4. How can I link the dialog from REST Endpoints to the listener? Or do I have to copy/paste the script into the Script field?
Can anyone help me with this? Thanks a lot!
Best regards
Nicole
Listeners, by their nature, are server-side and can't trigger anything on the browser-side.
What you are looking to do, is have a browser-side event based on the user adding an attachment that will trigger your dialog.
This is something that would have to be done in javascript and must be pretty much waiting for some DOM event to trigger a call to your REST api and create a new dialog with that data. This the same thing that is done by the webItem "show a dialog" option using scriptrunner-supplied javascript.
To call and create a dialog is no big deal... it looks like this:
var baseURL = AJS.$('meta[name="ajs-base-url"]').attr("content");
var issueKey = JIRA.Issue.getIssueKey();
AJS.$.ajax({
type: "GET",
dataType: "html",
url: baseURL + '/rest/scriptrunner/latest/custom/showDialog?issueKey='+ issueKey
}).done(function(data) {
AJS.dialog2($(data)).show();
}).fail(function(jqXHR, textStatus, errorThrown) {
console.warn("Failed to execute remote:", errorThrown);
});
But finding and registering an event that will detect the addition of an attachment in the screen will be more difficult (and not something I can do for you right now). It might get complicated by the vairious ways an attachment can be added (drag/drop, add attachment button, pasted on issue view, pastee/added in comment, pasted/adding in edit screen etc).
But the above would have to be in a resource file that's deployed using a Resource Web Fragment in the appropriate context to be available on the right screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.