Problem with refresh of issue detail view after linking issues via REST api.

Günter Halmans July 1, 2022

Hi,

I'm currently searching for a solution with regards to the following problem.

  • Goal: I wanted to implement a custom dialog (using Scriptrunner) where the User can select issues from a predefined dynamic selection list of issues (more or less like an Issue picker) and after he/she submits the dialog, the system links the current issue with the selected issue with a specific link type.
  • Hints according to the implementation: I reused the dialog-examples of the Scriptrunner documentation as well as some hints from the AUI documentation (e.g. according to dialog 2). I generated one REST Endpoint with the script and the Javascript to build the dialog. The REST Endpoint can be triggered by a Web Item - a menu entry in the "More" sequence of the issue detailed view. The links are generated by using REST api in the Javaspript functions concerning the submit button.
  • Current status: The dialog works fine so far - Selection list is generated correctly, the user is able to select issues, the submit-button leads to the wanted links.
  • Problem: After submitting the dialog, the issue detailed view is not refreshed correctly. In my first attempts, there was no refresh and one always had to use F5 to see the linked issues correctly in the "Issue Links" section. I added then the Jira triggerJIRA.trigger(JIRA.Events.REFRESH_ISSUE_PAGE, [JIRA.Issue.getIssueId()]); but this leads only to a presentation of the last selected issue to be linked (the user is able to link n issues with the current issue). I also tried to generate an additional Endpoint with an temporaryRedirection response (idea from Adaptavist support), but this also doesn't helped so far.
    Also Window.location.reload() or similar functions did not help. Only pushing F5 leads to the presentation of all linked issues. Or in case I delete one of the links after the dialog has been submitted, the link-container is refreshed correctly

My question: which function can/should I use to refresh the link section or complete detail view after or during submitting the dialog? Or in other words, what can I do that "F5 will be pushed" after the dialog has been submitted ;-)

I spended a lot of time in try&error without success and thus I would appreciate a solution idea very much!

Thanks in advance!

Best, Günter

2 answers

1 accepted

0 votes
Answer accepted
Carlos Garcia Navarro
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 3, 2022

Hi @GuenterH , I don't know the answer, but you may be able to find some hints here as well:  https://community.developer.atlassian.com/

Günter Halmans July 4, 2022

Hi Carlos,

unfortunately, I did not found a solution there...but thank you for this hint!

Best,

Günter

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 3, 2022

Hi @GuenterH

Could you please share the current code you are working with, along with some screenshots of the issue you are facing?

I will review it and provide some feedback.

Thank you and Kind regards,

Ram

Günter Halmans July 4, 2022

Hi Ram,

thank you in advance for giving me your feedback!

Please find enclosed (see below):

  1. pic01 -> screenshot of the Issue links section in the issue detailed view before I call the dialog
  2. pic02 -> the dialog where I select the issues to be linked to the current issue
  3. pic03 -> Issue Links section after submitting the dialog
  4. pic04 -> Issue Links section after additionally press F5
  5. the code of the dialog

I'm looking forward to your ideas!

Best regards,

Günter

 

1. pic01:

pic01.png

 

2. pic02:

pic02.png

 

3. pic03

pic03.png

 

4.pic04:

pic04.png

 

5. code:

showLink_Dialog {MultivaluedMap queryParams, String body, HttpServletRequest request ->

// section in which the selection list is generated --> optionString

dialog =
"""<section role="dialog" id="my-own-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true" data-aui-remove-on-hide="true">
<header class="aui-dialog2-header">
<h2 class="aui-dialog2-header-main">Assignment of Issues to current Issue</h2>
</header>
<div class="aui-dialog2-content">
<p>Please select one or multiple Issues from the following list:</p>
<form class="aui">
<select id="select2-example" multiple style="width:80%">
${optionString}
</select>
</form>
</div>
<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-actions">
<button id="dialog-close-button" class="aui-button aui-button-link">Cancel</button>
<button id="dialog-submit-button" class="aui-button aui-button-primary">Assign selected Issue(s)</button>
</div>
</footer>

<script>
AJS.\$("#select2-example").auiSelect2({
placeholder:'Select Issue(s)...',
allowClear: true,
width:'resolve',
search:true,
});

var resultSelection = AJS.\$('#select2-example').on('click', function () {
console.log("Selected values are: " + AJS.\$(this).auiSelect2('val'));
return AJS.\$(this).auiSelect2('val');
});

(function (\$) {
\$(function () {
AJS.dialog2.on("show", function (e) {
var targetId = e.target.id;
if (targetId == "my-own-dialog") {
var someDialog = AJS.dialog2(e.target);
\$(e.target).find("#dialog-close-button").click(function (e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
someDialog.hide();
someDialog.remove();
});
\$(e.target).find("#dialog-submit-button").click(function (e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
var homeUrl = "${baseUrl}/browse/${currentIssueKey}"

const arrayIssues = resultSelection.val().toString().split(",")
for (let i = 0; i < arrayIssues.length; i++) {
var url = "${baseUrl}/rest/api/2/issueLink";
var data = {
"type": {
"name": "CoW"
},
"inwardIssue": {
"key": "${currentIssueKey}"
},
"outwardIssue": {
"key": arrayIssues[i]
},
}

data = JSON.stringify(data)

let xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("X-AUSERNAME", "${user}");
xhr.setRequestHeader("X-Atlassian-Dialog-Control", "DONE");
xhr.onload = () => console.log(xhr.responseText);
xhr.send(data);

}// of for i...
someDialog.hide();
someDialog.remove();
JIRA.trigger(JIRA.Events.REFRESH_ISSUE_PAGE, [JIRA.Issue.getIssueId()]);

});
}
});
});
})(AJS.\$);
</script>

</section>
"""
Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build();
}

Suggest an answer

Log in or Sign up to answer