Sometimes you might just want to display some extra information about the issue, and not be able to search it. If you like, your script can output HTML, and you effectively don’t use a velocity template. This is similar to the now obsolete "velocity-processed custom field for view", but on steroids.

In this case use the HTML template option. There’s no point in enabling a searcher as there is not one that can handle HTML.

As an example, let’s say we want to draw attention to an issue when it is blocked by other issues that are not resolved, and not assigned. (Or not scheduled, not reviewed, whatever).

The field on the screen will look like this:

blockedIssuesWarning

In the code below I use a MarkupBuilder, although feel free to just construct a string containing html and return that. As usual return null if there are no blocking issues, so the field is not displayed at all.

package com.onresolve.jira.groovy.test.scriptfields.scripts

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import groovy.xml.MarkupBuilder
import com.atlassian.jira.config.properties.APKeys

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def baseUrl = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)

def List<Issue> blockingIssues = []

issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
    if (issueLink.issueLinkType.name == "Blocks") {
        def linkedIssue = issueLink.sourceObject
        if (!linkedIssue.assigneeId && !linkedIssue.resolutionObject) {
            blockingIssues.add(linkedIssue)
        }
    }
}

if (blockingIssues) {
    StringWriter writer = new StringWriter()
    MarkupBuilder builder = new MarkupBuilder(writer)

    builder.div (class:"aui-message error shadowed") {
        p (class: "title") {
            span (class: "aui-icon icon-error", "")
            strong ("This issue is blocked by the following unresolved, unassigned issue(s):")
        }

        ul {
            blockingIssues.each {anIssue ->
                li {
                    a(href:"$baseUrl/browse/${anIssue.key}", anIssue.key)
                    i(": ${anIssue.summary} (${anIssue.statusObject.name})")
                }
            }
        }
    }

    return writer
}
else {
    return null
}

Template

HTML

Searcher

None

For how-to questions please ask on Atlassian Answers where there is a very active community. Adaptavist staff are also likely to respond there.

Ask a question about ScriptRunner for JIRA, for for Bitbucket Server, or for Confluence.