Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Complex Workflow

pokalav September 19, 2017

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

Comment

Log in or Sign up to comment
Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 20, 2017

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

pokalav September 21, 2017

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.

Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2017

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. :)

pokalav September 21, 2017

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

pokalav September 22, 2017

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

Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2017

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)
Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2017
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)
}
}
}
}
}
}
pokalav September 25, 2017

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

Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2017

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

pokalav September 26, 2017

Hi Aidan,

   Yes changed but it's still not working.

 

Thanjs

Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2017

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

pokalav September 26, 2017

Hi Aidan,

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

Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2017

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

pokalav September 26, 2017

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)
Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 27, 2017

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 

pokalav September 28, 2017

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

pokalav September 29, 2017

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

Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 10, 2017

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

TAGS
AUG Leaders

Atlassian Community Events