Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner post-function update linked issue status and add comment

Hello,

I'm want to use a post-function with ScriptRunner to update the status and add a comment into the linked issue that is in an other projet.

So I have issue SUP-100 that was cloned (with exocet) into projet DEV and are linked together. my SUP task is in pending for the work to be completed in DEV. When they complete this issue I want it to trigger a post function to transistion the linked task into open status.

I've looked into other ways and I found this previous post here.

I've took the script and change what I really needed it to do but when it run (no error) nothing is happening to my other issue. 

Here my script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
def issueService = ComponentAccessor.getIssueService()
def linkType = ["Escalated"]
// 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.getUserManager().getUserByName("jirabot").getDirectoryUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
// Look through the outward links
for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
def destIssue = link.getDestinationObject()
// Prepare our input for the transition
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setStatusID("Open")
setComment("Linked task was completed, hence status changed to open")
setSkipScreenCheck(true)
}
// Validate transitioning the linked issue to "Signs Needed"
def validationResult = issueService.validateTransition(user, destIssue.id, 41, issueInputParameters)
if (validationResult.isValid()) {
// Perform the transition
def issueResult = issueService.transition(user, validationResult)
if (! issueResult.isValid()) {
log.warn("Failed to transition task ${destIssue.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition task ${destIssue.key}, errors: ${validationResult.errorCollection}")
}

}

I'm open to use other methode if it get the status updated so I can get this automated.

I'm not an expert in javascript but I'm trying to learn more about it so I can automate more within our Jira projet.

Thank you in advance

My current version of Jira is  7.6.1

2 answers

0 votes
brbojorque Community Leader Dec 17, 2019

It looks you updated the {destIssue} outside the loop, put it back inside the loop so it will make sure that all the links will be transitioned.

@Martin LALONDE 

Here is code if you have questions dm me.

import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.bc.issue.comment.CommentService
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issueManager = ComponentAccessor.getIssueManager()
def commentManager = ComponentAccessor.getCommentManager()
def issueLinkManager = ComponentAccessor.issueLinkManager

//Go into workflow where you want to transition issue and put the name of your transition that is before your STATUS in which you want to transition your issue
final actionName = 'Corrections Needed'
// Logger
def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.INFO)

// Put the name of user that will triger the transition
def user1 = ComponentAccessor.getUserManager().getUserByName("jirabot")
List<String> linkTypes = ["Escalated"] // anem of your linked type
Issue devIssue

// Insted of SCR put the key of your own project in which you will look for linked issues
List allOutIssueLink = issueLinkManager.getOutwardLinks(issue.id)
for (Iterator outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
if (issueLink.getDestinationObject().key.contains('SCR')) {
devIssue = issueLink.getDestinationObject()
}
}
def myComment = "My comment"

ComponentAccessor.commentManager.create(devIssue, user1, myComment, false)

def transitionIssue = devIssue.getId()

def workflow = ComponentAccessor.workflowManager.getWorkflow(devIssue)
myLog.info("workflow: " + workflow.name)
def actionId = workflow.allActions.findByName(actionName)?.id
myLog.info("actionId: " + actionId)
def transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

def issueService = ComponentAccessor.issueService
def issueInputParameters = issueService.newIssueInputParameters()


def transitionValidationResult = issueService.validateTransition(user1, transitionIssue, actionId, issueInputParameters, transitionOptions)
assert transitionValidationResult.isValid(): transitionValidationResult.errorCollection

def result = issueService.transition(user1, transitionValidationResult)
assert result.isValid(): result.errorCollection

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

188 views 6 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you