Hello,
*Using scriptrunner*
I have a script field that is returning a number value. I would like to display it as a Link but keeping the field as a number. When I display it as a Link using HTML templating and text searcher, I am not able to use this script field for other calculations as it is seen as a String. Is there a way to keep the value double and have it displayed as a Link?
This is the code of my script field:
import com.atlassian.jira.component.ComponentAccessor
import groovy.xml.MarkupBuilder
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def links = issueLinkManager.getOutwardLinks(issue.id)
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
def cfManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def linkMgr = ComponentAccessor.getIssueLinkManager()
def totalField = cfManager.getCustomFieldObject("customfield_10420")
double totalInvoiced = 0
//Invoice link
def invoiceLink = linkMgr.getInwardLinks(issue.id).findAll{it.getLinkTypeId() in [11024L]}
log.debug(invoiceLink)
// In case invoiced
if (invoiceLink){invoiceLink?.each{ invoice ->
def invoiceIssue = invoice.getSourceObject()
totalInvoiced += invoiceIssue.getCustomFieldValue(totalField)?.toDouble() ?: (double)0
}
}
def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl") + "/issues/?filter="
def query1 = "issuetype = \"Invoice\" AND CF[10963] > 0 and cf[10246] = \"${issue.key}\" "
def string1 = baseUrl + createUrlString(query1)
xml.a( href : "${string1}" ) {
span class:"class"
xml.mkp.yield "${totalInvoiced}"
}
return (writer.toString()) as double
def createUrlString(query){
def jqlString = "&jql="
def stringo = query.toString()
stringo.each{ w ->
if(w == " "){
jqlString = jqlString + "%20"
} else if (w == "'" || w == "\'" || w == "\""){
jqlString = jqlString + "%27"
} else if(w == "="){
jqlString = jqlString + "%3D"
} else if(w == "["){
jqlString = jqlString + "%5B"
} else if (w == "]"){
jqlString = jqlString + "%5D"
} else if (w == "%"){
jqlString = jqlString + "%25"
} else if (w == ":"){
jqlString = jqlString + "%3A"
} else if (w == ","){
jqlString = jqlString + "%2C"
} else {
jqlString = jqlString + w
}
}
return jqlString
}