1. I made a button using 'Script Fragments' that will call a 'REST Endpoints' script. The button made for the user a mail with all of the issue details.
When I clicked the button in the issue view, It worked perfectly.
When I tried to click the button from the Board:

I got this error:

Attached the script fragments script and the script REST Endpoints script.
This is the full link of the script fragments:
/rest/scriptrunner/latest/custom/PublishMailDialog?issueId=$issueId&issueKey=$issue.getKey()
Atlassian and Adaptavist support told me this is a coding problem inside the REST, In the HTML part.. Can you help me to understand what is the problem?
This is my code (I removed all of the definition of values , So ignore it)
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
import javax.servlet.http.HttpServletRequest;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import org.apache.commons.lang.StringUtils
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpMethod
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.lang.StringUtils
import groovy.json.*
import com.atlassian.crowd.embedded.impl.ImmutableGroup
import com.atlassian.jira.issue.customfields.impl.MultiGroupCFType
import com.atlassian.jira.issue.fields.NavigableField
import com.atlassian.jira.issue.fields.FieldManager;
import com.atlassian.jira.issue.RendererManager;
@BaseScript CustomEndpointDelegate delegate
PublishMailDialog() { MultivaluedMap queryParams ->
def issueId = queryParams.getFirst("issueId") as String
String issueKey // use the issueId to retrieve this issue
String parentId
for (String theKey: queryParams.keySet()) {
String value = queryParams.get(theKey);
if (theKey.equals("issueKey")) {
issueKey = value
issueKey = issueKey.substring(1); // trimming the leading'['
issueKey = issueKey.substring(0, issueKey.length() - 1); // trimming the ending'['
}
}
//Test preview
issueId = queryParams.getFirst("issueId") as String
//test
IssueManager issueManager = ComponentAccessor.getIssueManager();
Issue issue = issueManager.getIssueObject(Long.parseLong(issueId));
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def groupManager = ComponentAccessor.groupManager;
def groups = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("E-mail Recipients")) as List;
if(groups==null)
{
def dialog =
"""
<html>
<head>
<script>
function goBack() {
window.history.back()
}
</script>
<style>
body {
font-family: 'Open Sans', sans-serif;
font-size: 14px;
text-align: center;
}
h1 {
font-size: 15px;
color: #333;
line-height: 22px;
font-weight: bold;
}
.reportheader {
border-bottom: #F86E00 1px solid;
margin-bottom: 7px;
text-align: center;
}
div {
text-align: center;
}
#1 {
text-align: center;
}
.logo {
width: 65px;
float: right;
margin: 6px 0px 0px 0px;
}
.st1 {
fill: #FE5000;
}
.st0 {
fill: #414042;
}
</style>
</head>
<body>
<div id="1">
<br><br><br><br>
<div class="reportheader"><h1>For publish mail, You need to fill "E-mail Recipients" field</h1></div>
<br><br>
<div class="aui-dialog2-footer-actions" style="color:#333; font-size: 15px; text-align:center; font-family:'Open Sans', sans-serif; font-weight: bold;">
<button onclick="goBack()">Close</button>
</div>
</div>
</body>
</html>
"""
Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}
else
{
groups= groups.getAt(0) as ImmutableGroup;
log.warn groups;
log.warn fixVersion;
def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl");
log.warn baseUrl
def baseurlIssue = baseUrl+'/browse/'+issue;
log.warn baseurlIssue
def fieldManager = ComponentAccessor.getFieldManager()
def fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("description")
def field = fieldManager.getField("description")
NavigableField navigableField = (NavigableField)field
def descriptionHTML = navigableField.getColumnViewHtml(fieldLayoutItem, new HashMap(), issue)
def dialog =
"""
<html>
<head>
<script>
function goBack() {
window.history.back()
}
</script>
<style>
body {
font-family: 'Open Sans', sans-serif;
max-width: 800px;
font-size: 14px;
display: block;
margin: 8px;
}
a {
font-family: 'Open Sans', sans-serif;
color: #00A79D;
opacity: 0.8;
}
h1 {
font-size: 15px;
display: inline-block;
color: #333;
line-height: 22px;
font-weight: bold;
}
.reportheader {
border-bottom: #F86E00 1px solid;
margin-bottom: 10px;
}
div {
display: block;
}
h2 {
display: block;
color: #F86E00;
font-size: 14px;
margin: 0px 0px 10px 0px;
}
.reportpropertywrapper {
margin-left: 10px;
}
h3 {
color: #333333;
font-size: 14px;
margin: 0px 0px 0px 0px !important;
}
p {
color: #666;
margin-top: 5px;
margin-left: 10px;
margin-bottom: 10px;
}
h4 {
margin: 0px !important;
font-size: 12px;
color: #333333;
}
* {
transform-origin: 0px 0px 0px;
}
.logo {
width: 65px;
float: right;
margin: 6px 0px 0px 0px;
}
.st1 {
fill: #FE5000;
}
.st0 {
fill: #414042;
}
</style>
</head>
<body>
<div class="reportheader">
<h1>This mail will send to group: '${groups.getName()}'</h1><br>
<h1>Issue Report for Bug Customer Key <a href='${baseurlIssue}'>${issue}</a></h1></div>
<div class="reportsection"><h2></h2>
<div class="reportpropertywrapper"><h3>Description</h3>
<h4></h4>
<p>${issue.getSummary()}</p>
</div>
<div class="reportpropertywrapper"><h3>Product Name</h3>
<h4></h4>
<p>${ProductName}</p>
</div>
<div class="reportpropertywrapper"><h3>Version</h3>
<h4>The version on which the bug was found</h4>
<p>${Inversion}</p>
</div>
<div class="reportpropertywrapper"><h3>Steps to reproduce</h3>
<h4></h4>
<p>${descriptionHTML}</p>
</div>
<div class="reportpropertywrapper"><h3>Root cause & Suggested solution (in code)</h3>
<h4></h4>
<p>${RootCause}</p>
</div>
</div>
<div class="reportsection"><h2>Priority & Severity</h2>
<div class="reportpropertywrapper"><h3>Regression?</h3>
<h4></h4>
<p>${Regression}</p>
</div>
<div class="reportpropertywrapper"><h3>Regression to version</h3>
<h4></h4>
<p>${RegressionInVersion}</p>
</div>
<div class="reportpropertywrapper"><h3>Impact on customer experience</h3>
<h4>Low/Medium/high</h4>
<p>${issue.getPriority().name}</p>
</div>
<div class="reportpropertywrapper"><h3>Workaround</h3>
<h4></h4>
<p>${Workaround}</p>
</div>
</div>
<div class="reportsection"><h2>Fix For</h2>
<div class="reportpropertywrapper"><h3>Effort estimation</h3>
<h4>In story points</h4>
<p>${StoryPoints}</p>
</div>
<div class="reportpropertywrapper"><h3>Risk estimation</h3>
<h4>Areas or functionality that may be affected by the fix</h4>
<p>${RiskEstimation}</p>
</div>
<div class="reportpropertywrapper"><h3>Target fix pack</h3>
<h4></h4>
<p>${if(issue.getStatus().name!='Done'){fixVersion} else{return 'NA'}}</p>
</div>
</div>
<div class="reportsection"><h2>Solution</h2>
<div class="reportpropertywrapper"><h3>Commit ID</h3>
<h4></h4>
<p>Filled automatically from GIT</p>
</div>
<div class="reportpropertywrapper"><h3>Fixed in version</h3>
<h4></h4>
<p>${if(issue.getStatus().name=='Done'){fixVersion} else{return 'NA'}}</p>
</div>
<div class="reportpropertywrapper"><h3>Testing guidelines</h3>
<h4></h4>
<p>See steps to reproduce (no field is required, should be in the text written in the description field)</p>
</div>
<div class="reportpropertywrapper"><h3>Manager approved</h3>
<h4></h4>
<p>${ManagerName}</p>
</div>
</div>
</body>
<footer>
<div>
<form method="get" id ="fConvert">
<input type="hidden" name="issueId" value="${issueId}">
<br><br>
<h1>Please confirm that you wish to Publish this mail</h1>
<br>
<button type="submit" onClick="this.form.submit(); this.disabled=true;">Publish</button>
</form>
<button onclick="goBack()" id="dialog-close-button" class="aui-button aui-button-link">Cancel</button>
<script>
document.getElementById("fConvert").action = "/rest/scriptrunner/latest/custom/PublishMail";
</script>
</div>
</footer>
</html>
"""
Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}
}
Thanks,
Daniel