Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Listener for "Attachment added" and open a REST Endpoint link

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

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 23, 2022

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events