Transition a linked issue when parent/source issue performs a transition : Scriptrunner

Hi everyone,

After doing some research online, and editing/adding some script I came up with a postfunction that is suppose to transition a linked issue in another project.

 When the source issue gets moved from populate to review, I want the other issue(linked issue) within another project to get moved from Display to Not Display.  This post funtion lies in the source issue transition.  Can somone help me and let me know what I need to change to make the issues transition properly. My script and the logs are displayed below:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)

def issueService = ComponentAccessor.getIssueService()
def linkType = ["relates to"]
// 6.x validateTransition wants a User, so we have to use getDirectoryUser()
// 7.x validateTransition wants an ApplicationUser, so remove the .getDirectoryUser() after we upgrade
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
// Look through the outward links
log.debug("commence for loop")
for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
    log.debug("entered for loop")
    def destIssue = link.getDestinationObject()
    // Does the name of the link match "relates to" ?
    if (linkType.contains(link.issueLinkType.name)) {
        log.debug("relates to is the link type")
        def destStatusObject = destIssue.getStatus()
 // Is the status of the linked issue "Display" ?
        if (destStatusObject.name == "Display") {
            // Prepare our input for the transition
            log.debug("Status == Display")
            def issueInputParameters = issueService.newIssueInputParameters()
            issueInputParameters.with {
                setComment("Cancelled Vacation Request by HR")
                setSkipScreenCheck(true)
            }
            // Validate transitioning the linked issue to "Signs Needed"
            def validationResult = issueService.validateTransition(user, destIssue.id, 61, issueInputParameters)
            if (validationResult.isValid()) {
                log.debug("Validation Result is valid")
                // Perform the transition
                def issueResult = issueService.transition(user, validationResult)
                if (! issueResult.isValid()) {
                    log.debug("Failed to transition task ${destIssue.key}, errors: ${issueResult.errorCollection}")
                }
            } else {
                log.debug("Could not transition task ${destIssue.key}, errors: ${validationResult.errorCollection}")
            }
        } else {
            log.debug("Skipping link: ${link.issueLinkType.name} ${destIssue.key} ${destStatusObject.name} (wrong status)")
        }
    } else {
        log.debug("Skipping link: ${link.issueLinkType.name} ${destIssue.key} (wrong type)")
    }
}

 

2017-07-10 14:01:48,811 DEBUG [acme.CreateSubtask]: commence for loop
2017-07-10 14:01:48,811 DEBUG [acme.CreateSubtask]: entered for loop
2017-07-10 14:01:48,812 DEBUG [acme.CreateSubtask]: relates to is the link type
2017-07-10 14:01:48,812 DEBUG [acme.CreateSubtask]: Status == Display
2017-07-10 14:01:48,851 WARN [contact.ContactSelectCF]:  ContactSelectCF getValueFromCustomFieldParams 
2017-07-10 14:01:48,851 WARN [contact.ContactSelectCF]:  ContactSelectCF getValueFromCustomFieldParams singleParam 11417
2017-07-10 14:01:48,851 WARN [contact.ContactSelectCF]:  ContactSelectCF getValueFromCustomFieldParams option 11417 : Not defined
2017-07-10 14:01:48,851 WARN [contact.ContactSelectCF]: ContactSelectCF validateFromParams crm org option null for OAG-39
2017-07-10 14:01:48,851 WARN [contact.ContactSelectCF]:  ContactSelectCF :: store put Not defined : 19342_customfield_11711

 

1 answer

1 accepted

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,129 views 13 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot