Complex Workflow

Hi Team,

 

    Could anyone please help me the Script for below requirementWorkflowSTORY.pngworkflowBUG.png

 

Bug Transition.        Causes the following in the Story:

Reproduced                      Do All Scanned check

 

All Scanned:   

If Story Stage = “Scanning” and If for all Bug’s Stages != “Triage”, do Scanned All Models transition 

Note: Bug issue blocks the Story

Please help me as soon as possible

 

Thanks,

Venkatesh.

1 comment

Hey Venkatesh!

So I think the easiest way to accomplish this would be to use a ScriptRunner Fast-Track post-function.

All you would need to do is create the post-function on the "Scanning" stage of your workflow and then use a condition that checks all of the bugs that block the story and checks that their current stage is not equal to "Triage."

Try out something like this:

import com.atlassian.jira.component.ComponentAccessor

def linkManager = ComponentAccessor.issueLinkManager

//Check that issue is of type Story
if(issue.issueType.name == "Story")
{
//Get all inward links that are bugs
def links = linkManager.getInwardLinks(issue.id).findAll{it.sourceObject.issueType.name == "Bug"}
links.each{log.warn("Link: "+it.sourceObject.issueType.name)}
for(def i=0; i<links.size(); i++)
{
def link = links[i]
if(link.issueLinkType.name == "Blocks")
{
def blocker = link.sourceObject
log.warn("Blocker: "+blocker.key)
if(blocker.status.name in ["Triage"])
{
//If the Bug is in one of those stages, do not transition the Story
return false
}
}
}
return true
}
else
{
//Do not do attempt fast-track if issue is not a Story
return false
}

Then all you need to do is specify which Action to take in the case that the condition resolves to True. In this case, you choose the Scanned All Models transition. 

Try that out and let me know if you have any questions! :D

Aidan

Hi Aidan,

 

     Under which path we need to paste this script? We are tried this in Story workflow -->under all scanned mode transition--->script postfunction---> fast track--> added the script in Condition tab and selected Action(All Scanned mode).

Image_from_Skype.png

Imaqge_from_Skype.png

But above method is not working.

 

Note: If Story(Sccaning) is blocked by 3 Bugs(Triage).

If we move all Bugs Triage to Inprogress then only the Story should move(do all scanned modes) Scanning to Inprogress

 

Thanks

Venkatesh.

So for this case, you're going to need to add the fast-track to ALL of the transitions that lead to the Scanning stage. That way, any time a Story is transitioned to Scanning, it will run the check to fast-track or not fast-track the issue to In Progress.

Additionally, try moving the post-functions to the 3rd position in the execution order, above "Update change history for an Issue..."

Make those changes and see if that did the trick. :)

Hi Aidan,

        Understood but here the scanning is a story status, please help with the step by step process.

      Note : Now the story status is scanning and its blocked by multiple bugs ( Triage ) After moving all the bugs from Triage to Inprogress, the story status should move from scanning to inprogress.

 

Bascially the requirment is, mutliple bugs transistion to single story transistion

Thanks,

Venkatesh

Hi Aidan,

        Understood but here the scanning is a story status, please help with the step by step process.

      Note : Now the story status is scanning and its blocked by multiple bugs ( Triage ) After moving all the bugs from Triage to Inprogress, the story status should move from scanning to inprogress.

 

Bascially the requirment is, mutliple bugs transistion to single story transistion

Thanks,

Venkatesh

Hey again Pokala!

I think I accidentally misunderstood you the first time, sorry!

So, now that I'm back on track, what you actually need to do is use a post-function on your "Reproduced" transition for your bugs (and maybe the Re-Open transition, but that's your choice).

Requirements:

Then you'll need a script that checks that the transitioned issue is a bug, that it is linked to a story, and that all of that story's blocking bugs are in the status "In Progress." If all of the story's bugs are "In Progress," transition the story to "In Progress" from "Scanning."

Steps to Implement:

  • Go to the bug's workflow (Diagram view)
  • Click the Reproduced transition and click post-functions
  • To add a post function do: Add Post Function - Script Post-function - Custom script post-function
  • Then use a script that checks and accomplishes the requirements specified above. (I'll post an example of mine that you can use below)
import com.atlassian.jira.component.ComponentAccessor

//Define necessary managers/components
def currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def issueManager = ComponentAccessor.issueManager
def issueService = ComponentAccessor.issueService
def linkManager = ComponentAccessor.issueLinkManager

//Get MutableIssue of issue in event
def issue = issueManager.getIssueByCurrentKey(event.issue.key)

def issueInputParameters = issueService.newIssueInputParameters()
def actionId = 21 // change this to the step that you want the issue to be transitioned to
def transitionValidationResult
def transitionResult
//log.warn("The issue type is: " + issue.getIssueType().name)

//check that issue is a bug
if (issue.getIssueType().name == "Bug") {

//Get outward links and check for link type Blocks
linkManager.getOutwardLinks(issue.id).each{
//log.warn("Link Type: "+it.issueLinkType.name)
if(it.issueLinkType.name == "Blocks")
{
//Check that blocked issue is a Story and has a specific status
def blockedIssue = it.destinationObject
if(blockedIssue.issueType.name == "Story" && blockedIssue.status.name in ["Scanning"])
{
//Get the Story's linked bugs
def storyBugs = linkManager.getInwardLinks(issue.id).findAll{it.sourceObject.issueType.name == "Bug"}
def canTransition = true

//Check that all bugs are in the status "In Progress"
for(link in storyBugs)
{
if(link.issueLinkType.name == "Blocks")
{
def linkedBug = link.sourceObject
//If one of the bugs is not "In Progress," then set canTransition to false and break from loop
if(!(linkedBug.status.name in ["In Progress"]))
{
canTransition = false
break
}
}
}

//Will transition if ALL bugs were in status "In Progress"
if(canTransition)
{
//log.warn("Attmepting Transition")
//Validate the issue transition
transitionValidationResult = issueService.validateTransition(currentUser, blockedIssue.id, actionId, issueInputParameters)

if (transitionValidationResult.isValid()) {
//Attempt to transition the issue
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $blockedIssue.key through action $actionId") }
else
{
log.debug("Transition result is not valid")
log.debug("ErrorCollection: "+transitionValidationResult.errorCollection)
}
}
else {
log.debug("The transitionValidation is not valid")
log.debug("ErrorCollection: "+transitionValidationResult.errorCollection)
}
}
}
}
}
}

Hi Aidan,

 

       I have tried with above script bu.t it's not working. Kindly provide the exact script to match our request.

 

Note: If i have 3 bugs and all in Triage status, once i moved all the three to In progress, then story should move from scanning to inprogress.

 

Story "is blocked by" multiple bugs

 

Thanks

Hiya Pokala!

I forgot to mention this in my last comment, but did you alter this line of code to match the ID of your Story's "In Progress" transition?

def actionId = 21 // change this to the step that you want the issue to be transitioned to

If you don't change this ID, then the Story may try to transition to a stage that it is unable to! 

Aidan

Hi Aidan,

   Yes changed but it's still not working.

 

Thanjs

I'm going to need a little bit more detail.

What do you mean when you say that it isn't working? Is it doing nothing? How are you testing it? What do you expect to happen? Give me a use-case that you've tested so that I can trace through the code to see the issue.

Additionally, could you give me a screenshot of the post-function's location in the execution order?

Thanks! :D

Hi Aidan,

     Clearly i have added the comments in attached image, please check and advise.JIRABUG.pngReproducedBUG.pngPOSTfunction.pngCustomScript.png61.png

Thanks for that!

In the screenshot of the execution order, there is a line that reads "15 of 15 failed..." Could you expand that by clicking on it and see what errors are being thrown?

Share them with me, either via a screenshot or via a copy/paste. 

Aidan

Time (on server): Tue Sep 26 2017 19:37:04 GMT+0530 (IST)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-09-26 07:07:04,674 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-09-26 07:07:04,674 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: VMS-32, actionId: 111, file: <inline script>
groovy.lang.MissingPropertyException: No such property: event for class: Script1
 at Script1.run(Script1.groovy:10)

OOOOHHH that is entirely my bad haha! :D

Good thing we checked the error message, or I would have been confused for a while. I had originally set this script up for a script listener and was using Event object to get the Issue object, which will definitely not work in a post-function. 

So to fix this, all you should need to do is remove these two lines of code:

//Get MutableIssue of issue in event
def issue = issueManager.getIssueByCurrentKey(event.issue.key)

Test the code again with those lines removed and let me know if it starts working for you after that. :)

Best of Luck,

Aidan 

Hi Aidan,

 

    Thank you so much!

 

It's working fine.  We need another transition condition have tried with changing statuses in script for this but it's not working. 

 

When all Bugs are in stage "In Test", "Pending Release", "Hotfix", or "Closed" do all fixed check

 

import com.atlassian.jira.component.ComponentAccessor

//Define necessary managers/components
def currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def issueManager = ComponentAccessor.issueManager
def issueService = ComponentAccessor.issueService
def linkManager = ComponentAccessor.issueLinkManager

//Get MutableIssue of issue in event
//def issue = issueManager.getIssueByCurrentKey(event.issue.key)

def issueInputParameters = issueService.newIssueInputParameters()
def actionId = 101 // change this to the step that you want the issue to be transitioned to
def transitionValidationResult
def transitionResult
//log.warn("The issue type is: " + issue.getIssueType().name)

//check that issue is a bug
if (issue.getIssueType().name == "Bug") {

    //Get outward links and check for link type Blocks
    linkManager.getOutwardLinks(issue.id).each{
        //log.warn("Link Type: "+it.issueLinkType.name)
        if(it.issueLinkType.name == "Blocks")
        {
            //Check that blocked issue is a Story and has a specific status
            def blockedIssue = it.destinationObject
            if(blockedIssue.issueType.name == "Story" && blockedIssue.status.name in ["In Progress"])
            {
                //Get the Story's linked bugs
                def storyBugs = linkManager.getInwardLinks(issue.id).findAll{it.sourceObject.issueType.name == "Bug"}
                def canTransition = true

                //Check that all bugs are in the status "In Progress"
                for(link in storyBugs)
                {
                    if(link.issueLinkType.name == "Blocks")
                    {
                        def linkedBug = link.sourceObject
                        //If one of the bugs is not "In Progress," then set canTransition to false and break from loop
                        if(!(linkedBug.status.name in ["In Test"]))
                        {
                            canTransition = true
                            break
                      }
                    }
                }

                //Will transition if ALL bugs were in status "In Progress"
                if(canTransition)
                {
                    //log.warn("Attmepting Transition")
                    //Validate the issue transition
                    transitionValidationResult = issueService.validateTransition(currentUser, blockedIssue.id, actionId, issueInputParameters)

                    if (transitionValidationResult.isValid()) {
                        //Attempt to transition the issue
                        transitionResult = issueService.transition(currentUser, transitionValidationResult)
                        if (transitionResult.isValid())
                        { log.debug("Transitioned issue $blockedIssue.key through action $actionId") }
                        else
                        {
                            log.debug("Transition result is not valid")
                            log.debug("ErrorCollection: "+transitionValidationResult.errorCollection)
                        }
                    }
                    else {
                        log.debug("The transitionValidation is not valid")
                        log.debug("ErrorCollection: "+transitionValidationResult.errorCollection)
                    }
                }
            }
        }
    }
}

As per the condition have changed statuses. But it's not working.

 

 

Kindly help me.

 

Thanks,

Venkatesh

Hi Aidan,

Everything is Okay!

          Please advise the script for below requirement, we added a "Primary" field in BUG while creating issue as "True" or "False" so now selecting "True" this should work.

The story should move from "In Validation" to "Scanning"

the condition is

When Bug where in Primary custom field is true moves from In Validation to In Progress.

 

Note : The Multiple Bug is Blocks the Story.

Thanks,

Venkatesh

Hey Pokala!

I've answered this same question over on:

https://community.atlassian.com/t5/Product-Apps-questions/Scripting-Transition/qaq-p/647474#U652842

Let me know if that's what you're looking for and accept my answer on this question for others to see if you're satisfied.

Aidan :D

Comment

Log in or Sign up to comment
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,787 views 18 22
Read article

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