It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner fragment displays modal as entire page Edited

Hello,

I am attempting to create a button that opens a modal within the confluence UI using scriptrunner. I have created a web fragment which seems correct from the documentation. I have attached a screenshot of my configuration. I have linked my fragment to a REST endpoint. The REST endpoint is directly copied from https://scriptrunner.adaptavist.com/latest/jira/fragments/WebItem.html under the Dialogs (Advanced) section. 

After doing all of this, my modal appears alone with no styling in its own tab/page when my link is clicked. I am confused as to why it is not appearing as a modal on the same screen as the clicked button. Any help is appreciated.

ThankWebItem.PNG

1 answer

1 accepted

0 votes
Answer accepted

That might be a bug/design flaw in scriptrunner. Try to put the same webitem on a page menu instead.

For this web fragment config to work, scriptrunner has to make sure they deploy some javascript in a given context that will listen to this link-click event and create a dialog instead of using the default behavior of the link (which is to navigate tot eh url).

If you can't get them to fix it or don't want to wait, then you have to deploy your own javascript in that specific context and change the "Do What" dropdown to "Do Nothing I will write my own javascript".

Something like this has worked for me in a different context:

(function ($) {
$(function () {

$('body').off('click', '#your-web-item-key').on('click', '#your-web-item-key', function(event){
event.preventDefault();
var ancestorAnchor = $(this).closest("[href]");
AJS.$.ajax({
type: "GET",
dataType: "html",
url: ancestorAnchor.attr("href")
}).done(function(data) {
AJS.dialog2($(data)).show();
}).fail(function(jqXHR, textStatus, errorThrown) {
console.warn("Failed to execute remote:", errorThrown);
});
});

});
})(AJS.$);

This will bind the click event of your web item so that when you click it, it will prevent the navigation (preventDefault)  then fetch the content of your rest API using ajax by reading the href attribute and then display an AJS.dialog2 with the data retrieved from the rest api.

This page may be helpful: https://docs.atlassian.com/aui/8.6.0/docs/dialog2.html

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What project did you transition or start on Confluence with the shift to remote work?

It’s been great to hear from fellow users over the last few weeks about the best tips and fun moments you’ve had working on Confluence since the transition to working remote. I’d love to keep the c...

32 views 2 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you