Script Listener and Post Function unable to update another issue's Summary or FixVersions properties

 

Within the Script Listener or Post Function, we're referencing an issue's linked issues as MutableIssues and attempting to set the property (Summary and FixVersions) of those issues with the setSummary and setFixVersions methods. The end result is that the values are not changed. We are able to set the values of the originating event.issue or issue, but none of the linked issues properties. Example code below:

JIRA: 7.0.5

ScriptRunner: 4.2.0.5

// Determine if this is an Epic, if so, return the Epic Link name
if (issue.getIssueType().name == "Epic") {
   // Variables for the issue itself
    IssueLinkTypeManager issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
    IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
    Collection<IssueLinkType> storyLinkTypes = issueLinkTypeManager.getIssueLinkTypesByName('Epic-Story Link')
    Long storyLinkTypeId = storyLinkTypes[0].id
    // Defining Link Manager
    def optionsManager = ComponentAccessor.getOptionsManager()
    def issueManager = ComponentAccessor.getIssueManager()
    def fixVersion = issue.getFixVersions()
    // If the link type is Epic-Story Link
    if (storyLinkTypes) {
        // Iterating through all Links pertaining to Epic
        for (IssueLink link in issueLinkManager.getOutwardLinks(issue.id)) {
            // Checking the Epic-Story Link
            if (storyLinkTypeId == link.issueLinkType.id)
            {
                  def linkedIssueStatus = link.destinationObject.getStatus().getName()
                MutableIssue linkedIssue = issueManager.getIssueObject(link.destinationObject.getId())
                linkedIssue.setSummary("New Summary")
            }
        }
    }
}

 

1 answer

This widget could not be displayed.

Your script should look like the following:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager

if (issue.getIssueType().name == "Epic") {

    def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
    def issueLinkManager = ComponentAccessor.getIssueLinkManager()
    def issueService = ComponentAccessor.getIssueService()

    def storyLinkTypes = issueLinkTypeManager.getIssueLinkTypesByName('Epic-Story Link')
    def storyLinkTypeId = storyLinkTypes[0].id

    def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
    // If the link type is Epic-Story Link
    if (storyLinkTypes) {

        issueLinkManager.getOutwardLinks(issue.id)?.each { link ->
            if (storyLinkTypeId == link.issueLinkType.id) {
                def linkedIssue = link.destinationObject

                def updateParameters = issueService.newIssueInputParameters()
                updateParameters.setSummary("New Summary")

                def validationResult = issueService.validateUpdate(user, linkedIssue.id, updateParameters)

                if (validationResult.isValid()) {
                    issueService.update(user, validationResult)
                } else {
                    log.warn validationResult.errorCollection.errors
                }
            }
        }
    }
}

This uses IssueService to do the update for you for each of the linked issues which will save them in the database and reindex them.

Otherwise the post-function will only update and reindex the current issue that is being transitioned.

Hope this helps.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

573 views 25 15
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you