In this exercise, we’re going to extend the functionality of the “More” button in Jira Issues by adding a new option called “Cookie Procedure.” We’ll achieve this by leveraging Scriptrunner’s WebFragment to open a dialog. This enhancement will provide users with a seamless way to access cookie-related procedures directly from the issue interface.
Steps to Implement the “Cookie Procedure” Option
Test the integration to confirm that the new option works as intended without any conflicts or issues.
Setting Up the WebFragment:
- We’ll configure a Scriptrunner WebFragment to insert the new option into the “More” button dropdown.
- This involves defining the context and the location where the option will appear.


Creating the Dialog:
- The dialog that opens upon selecting “Cookie Procedure” will be crafted using Scriptrunner REST method.
- It will contain all necessary fields and actions related to the cookie procedure.
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
showDialog(httpMethod: "GET", groups: ["jira-software-users"]) { MultivaluedMap queryParams ->
def issueId = queryParams.getFirst("issueId") as String // use the issueId to retrieve this issue
// Return def type = queryParams.getFirst("type") as String // Possible values [TMS,SDK,DPO]
// get a reference to the current page...
// def page = getPage(queryParams)
def dialog =
"""
<section role="dialog" id="sr-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true">
<header class="aui-dialog2-header">
<h2 class="aui-dialog2-header-main">Cookies procedure</h2>
<a class="aui-dialog2-header-close">
<span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Close</span>
</a>
</header>
<div class="aui-dialog2-content">
<div id="container" style="width:px">
<form class="aui" id="my-custom-sr-dialog-form">
<p>
<i>If configuration through TMS is possible, DPO’s recommendation is to select "Cookie procedure TMS". If you continue with Hardcode configuration, remember that you will be responsible for the necessity and proportionality of the Cookie and for the applicability of the Privacy Principles</i>
</p>
<select name="type" id="type">
<option value="TMS">TMS</option>
<option value="SDK">Hardcoded/SDK</option>
<!--<option value="SDA">SDA</option>-->
</select>
<input id="issueId" class="text" type="hidden" name="issueId" value='"""+issueId+"""'></input>
</form>
</div>
</div>
<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-actions">
<button id="submit-button" class="aui-button aui-button-primary">Confirm</button>
<button id="dialog-close-button" class="aui-button aui-button-link">Close</button>
</div>
<div class="aui-dialog2-footer-hint">Cookies procedure</div>
</footer>
<script>
(function (\$) {
\$(function () {
AJS.dialog2.on("show", function (e) {
var targetId = e.target.id;
if (targetId === "sr-dialog") {
var someDialog = AJS.dialog2(e.target);
\$(e.target).find("#submit-button").click(function (button) {
this.disabled=true;
\$.ajax({
type: "GET",
url: AJS.contextPath() + "/rest/scriptrunner/latest/custom/cookieprocedure?"+ AJS.\$(document).find("#my-custom-sr-dialog-form").serialize(),
beforeSend: function (request) {
request.setRequestHeader("X-Atlassian-token", "no-check");
}
}).done(function(response) {
//do whatever needs done in the UI here
//alert("OK")
window.location.reload();
});
});
}
}
);
});
})(AJS.\$);
</script>
</section>
"""
Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}

Integrating with Jira:
- Ensure the WebFragment and dialog integrate smoothly with Jira’s existing functionality, and the final custom REST Endpoint.
- Test the integration to confirm that the new option works as intended without any conflicts or issues.
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.link.IssueLink
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
cookieprocedure(httpMethod: "GET", groups: ["jira-software-users"]) { MultivaluedMap queryParams ->
// the details of getting and modifying the current issue are ommitted for brevity
def issueId = queryParams.getFirst("issueId") as String // use the issueId to retrieve this issue
def type = queryParams.getFirst("type") as String // Possible values [TMS,SDK,SDA]
def targetProjectKey = ""
def targetProjectIssueTypeId = ""
if ( type == "TMS") {
targetProjectKey = "TMS"
targetProjectIssueTypeId = "xxxx" //issuetype xxxx
}
if ( type == "SDK") {
targetProjectKey = "SDK"
targetProjectIssueTypeId = "yyyy" //issuetype yyyy
}
if ( type == "SDA") {
targetProjectKey = "SDA"
targetProjectIssueTypeId = "dddd" //issuetype dddd
}
IssueManager issueManager = ComponentAccessor.getIssueManager();
def issue = issueManager.getIssueObject(issueId);
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueFactory = ComponentAccessor.getIssueFactory()
MutableIssue newissue = (MutableIssue) issueFactory.getIssue()
newissue.setSummary (issue.summary)
def projectMgr = ComponentAccessor.getProjectManager()
newissue.setProjectObject(projectMgr.getProjectObjByKey(targetProjectKey))
newissue.setIssueTypeId(targetProjectIssueTypeId) //The ID of the target Issue Type
newissue.setDescription(issue.description)
def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
newissue.setReporter(currentUserObj)
newissue.setAssignee(currentUserObj)
def params = ["issue":newissue]
def subTask = issueManager.createIssueObject(currentUserObj, (Map) params)
def linkMgr = ComponentAccessor.getIssueLinkManager()
linkMgr.createIssueLink (newissue.id, issue.id, Long.parseLong("zzzzz"),Long.valueOf(1), currentUserObj) //ZZZZZ is the id of the type of link
def flag = [
type : 'success',
title: type + " linked ticket created",
close: 'auto',
body : "The "+issueId+" has a new linked issue for the "+type+" <a href='https://jira.example.com/browse/"+ newissue.getKey() + "' target='new'>"+ newissue.getKey() + "</a>"
]
Response.ok(JsonOutput.toJson(flag)).build()
}
Finally you will create Linked Issues to different projects using this code, just test it!
MrAddon by TecnoFor by Sngular
#AtlassianCreator #Atlassian #Groovy #Dialog
.





