Scripting Transition

Deleted user September 28, 2017

Hi Team,

        Please advise the script for below requirement, we added a "Primary" field 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. 

 

1 answer

0 votes
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 3, 2017

Hey Jeeva!

Just to clarify the question:

So you have a custom field that appears upon issue creation for your issues of type Bug. When that custom field (AKA "Primary") is set to "True" on a bug and the bug is transitioned from "In Validation" to "In Progress," then its linked Story issue should be also transitioned from "In Validation" to "Scanning."

Is that correct?

Aidan

Deleted user October 3, 2017

Yes perfect. please advise the solution 

Deleted user October 3, 2017

Hi Aidan,

   Adding a point, we have added a script on the same transition in bug under post function from "In Validation" to "In Progress," please check the image.

and advise how to put two different script in single transition, does it affect? 

Screenshot from 2017-10-03 20-10-02.pngit affect? 

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.
October 10, 2017

Hey Jeeva! 

Two scripts on your transition shouldn't effect anything too drastically. Unless one of the scripts does something that would directly effect the other, then they shouldn't conflict.

As far as your first question, on the same transition that you've posted a screenshot of, you'll need to add another post-function with the following code:

import com.atlassian.jira.component.ComponentAccessor

def cfm = ComponentAccessor.customFieldManager
def linkManager = ComponentAccessor.issueLinkManager
def issueService = ComponentAccessor.issueService

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueInputParameters = issueService.newIssueInputParameters()
def actionId = 21 // change this to the step that you want the story to be transitioned to
def transitionValidationResult
def transitionResult

if(issue.issueType.name == "Bug")
{
def primary = cfm.getCustomFieldObjectByName("Primary")
def primaryValue = issue.getCustomFieldValue(primary)

if(primaryValue)
{
linkManager.getOutwardLinks(issue.id).each{
if(it.issueLinkType.name == "Blocks")
{
def destination = it.destinationObject
if(destination.issueType.name == "Story" && destination.status.name in ["In Validation"])
{
log.info("Attmepting Transition")
//Validate the issue transition
transitionValidationResult = issueService.validateTransition(currentUser, destination.id, actionId, issueInputParameters)

if (transitionValidationResult.isValid()) {
//Attempt to transition the issue
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{
log.debug("Transitioned issue $destination.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)
}
}
}
}
}
}

In the code that I've provided, you'll need to change the actionId variable value to the id of the Scanning transition in your story workflow. 

Test it out and see if it works for you. If not, let me know and we'll see what we can find out! :D

Aidan

Deleted user October 12, 2017

Thanks Aidan, 

That works, following please help this.

Subject : Resolution Type Change on Fixed/No Fix

On movement to Closed for Story the Resolution types are as follows:   When all or some Bugs have fixed resolutions (i.e. Fix Backend, Fix Pushed, or Fix Released) change resolution to Fixed.When no Bugs have fixed resolutions change resolution to No Fix

Please provide script for this. 

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 20, 2017

Hey again Jeeva!

Sorry it's taken me so long to get back to you!

I have just one clarifying question:

  1. What is your definition of "some" when you say "all or some?" Does some mean more than one, does it mean half of the bugs or more, etc...?

Once you get back to me I'll try to get an answer for you as soon as possible!

Thanks! :)

Aidan

Deleted user October 23, 2017

Hi Aidan,

Some examples. 

Resolution : No Fix

a.Bug A is Need More Info

b.Bug A is Cannot Reproduce, Bug B Is Won’t Fix, and Bug C is Unaffected

c.Bug A is Won’t Fix, Bug B is Won’t Fix

By doing this the resolution field value should move to "No Fix" Here we developed some script please refer and advise.

Note : Please look into below for your reference. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import java.lang.String

log.setLevel(org.apache.log4j.Level.DEBUG)
import org.apache.log4j.Level
import org.apache.log4j.Logger
Logger.getLogger("com.onresolve").setLevel(Level.DEBUG)

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

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

def issueInputParameters = issueService.newIssueInputParameters()
// 121 for intest to closed
def actionId = 121 // change this to the step that you want the issue to be transitioned to
// 191 for inprogress
//def inprogress_actionId = 191

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 Test","Scanning","In Progress","In Validation"])
{
log.warn("story Resolution field value: " + blockedIssue.resolution.name)
String res = "Resolution"
log.warn("====story resolution field value === : " + blockedIssue.getFieldByName(res))
//Get the Story's linked bugs
def storyBugs = linkManager.getInwardLinks(blockedIssue.id).findAll{it.sourceObject.issueType.name == "Bug"}
def canTransition_to_closed = true
def canTransition_to_inprogress = false
def canTransition_scanning_to_intest = false

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

}
}

def canSetStoryField = false
//set story resolution field as Fixed.
for(link in storyBugs)
{
if(link.issueLinkType.name == "Blocks")
{
log.warn("Issue resolution: " + issue.resolution.name)
def linkedBug1 = link.sourceObject
//If one of the bugs is not "In Test" then set canTransition to false and break from loop
if(linkedBug1.issue.resolution.name in ["Need More Info", "Unaffected", "Cannot Reproduce", "Won't Fix"])
{
canSetStoryField = true
break
}

}
}
log.warn("Can Set Story field: " + canSetStoryField)

if(canSetStoryField){
def option = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find {it.toString() == "No Fix"}
//blockedIssue.resolution.updateValue(null, blockedissue, new ModifiedValue(blockedIssue.resolution, option),changeHolder);
//IssueConstant issueResolutionConstant = constantsManager.getIssueConstantByName(ConstantsManager.CONSTANT_TYPE.RESOLUTION.getType(), "No Fix");
}

if(!(canTransition_to_closed)){
// ================
//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 Validation," then set canTransition true and break from loop
if(linkedBug.status.name in ["In Test", "Pending Release", "Hotfix", "Closed", "In Progress"])
{
canTransition_to_inprogress = true 
}
else
{ 
canTransition_to_inprogress = false
break
}

}
}
// =================

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

}
}
// =================


}

//Will transition if ALL bugs were in status "Closed"
if(canTransition_to_closed || canTransition_to_inprogress)
{
if(canTransition_to_closed){
actionId = 121
log.debug("==canTransition_to_closed==")
}
if(canTransition_to_inprogress){
actionId = 191
log.debug("==canTransition_to_inprogress==")
}
if(canTransition_scanning_to_intest){
log.debug("==canTransition_scanning_to_intest==")
actionId = 211
}
//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)
}
}// if statement closed
}
}
}
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events