Can I get a field value from a ticket that came back as a search result using Groovy?
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 16, 2024
In the following script if the "searchCriteria" returns a ticket I then need to get the "Workitem Type" from that found ticket to display in the current ticket (as part of the string header) . Is that possible to do?
I found a potential solution by iterating through all of the possible 'Workitem Types' but that seems to be resource intensive and then I get many unnecessary links on my current Jira ticket. 
package HOL.webFragments
import com.atlassian.jira.issue.Issue
import static*
import static*
import static*

class Links extends BaseLinkBuilder {

    void doGenerate(Writer writer, Issue issue) {
        String alternateIssueId = values(issue, "Alternate Issue ID")[0]
        String issueKey = issue.getKey()

        values(issue, 'Ticker').forEach {
            simpleLink(writer, 'Function Link', "${it} Equity ${PHDC[env]}", 'Launch PHDC')
        String holSummary = "US5 PSTK Update"
        if (issue.getSummary().contains(holSummary)) {
            String searchCriteria = "project = 'HOL' AND 'Alternate Issue ID' ~ '${alternateIssueId}' and summary ~ 'US5 PSTK Update' and key != '${issueKey}'"
            String header = "Tickets Bundled by Workitem ID:"
            jqlLink(writer, searchCriteria, 5, true, header)


1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2024

If this is run from within scriptrunner, you should be able to use HAPI to run that JQL search, then access, the resulting issue's custom field values.

def issues =

def workItemType = issue[0].getCustomFieldValue('Workitem Type')

 But that assumes that the Workitem Type you speak of is a custom field. Maybe that's in the context of some other third party app.

Suggest an answer

Log in or Sign up to answer