Can I get a field value from a ticket that came back as a search result using Groovy?

tbarrett@bloomberg.net
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 com.bloomberg.dtjira.Environment.*
import static com.bloomberg.dtjira.Utility.*
import static com.bloomberg.dtjira.Links.*
import com.bloomberg.dtjira.link.BaseLinkBuilder

class Links extends BaseLinkBuilder {

    @Override
    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 = Issues.search(searchCriteria).collect()

if(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