Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute auto transition in jira workflow from one status to another status

Shivaprasad Hattaraki
Contributor
June 18, 2018

I have one script field called  "Warranty Date Status" its value returns in HTML format( Valid  or Invalid),depending on these values i have to make auto transition from status "INPROGRESS" TO "VALID DATE" or  "INVALID DATE". 

Could You please help me out for this?

I have tried with Toolkit plugin but didn't work.

1 answer

0 votes
Suhas P
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.
June 18, 2018

It depends how the value of scripted field changes. Either you fire a custom event upon value set OR configure a Escalation service which will run in intervals to check the value and runs a script which transitions the issue. 

Have a look IssueService class for triggering the transition from script. I will try to make a script when I have time :)

IssueService.TransitionValidationResult
Shivaprasad Hattaraki
Contributor
June 19, 2018
import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager

def warrantyField = customFieldManager.getCustomFieldObjectByName("Valid Warranty Date")

def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()

if(warranty == null){
return("<p style=color:blue>Please Enter Valid Warranty Date</p>")
}else if(warranty < systemDate)
{
return("<p style=color:red>INVALID</p>")
}else
{
return("<p style=color:green>VALID</p>")

I have this code in script field based on these values i need to transit status automatically from "IN PROGRESS" to "VALID DATE" or "INVALID DATE".

could we able to do this using listener or not plz let me know if possible. 

Shivaprasad Hattaraki
Contributor
June 19, 2018

Hi Suhas,

Could you plz help me in  this issue?

Suhas P
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.
June 19, 2018

i think in the same script you can put code in IF statement to transition the issue. Transition issue code looks like this.

Try following code. Use respective transition ids in both if statements. You can find transition IDs in transition name. they are written in brackets (11) like this.

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def issueService = ComponentAccessor.getIssueService()

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def warrantyField = customFieldManager.getCustomFieldObjectByName("Valid Warranty Date")

def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()

def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setSkipScreenCheck(true)
}

if(warranty == null){
return("<p style=color:blue>Please Enter Valid Warranty Date</p>")

def validationResult = issueService.validateTransition(user, issue.id, transitionID, issueInputParameters) //actionID is transition id, you can see it in the workflow
if (validationResult.isValid()) {
// Perform the transition
def issueResult = issueService.transition(user, validationResult)

}

}else if(warranty < systemDate)
{
return("<p style=color:red>INVALID</p>")

def validationResult = issueService.validateTransition(user, issue.id, transitionID_2, issueInputParameters) //actionID is transition id, you can see it in the workflow
if (validationResult.isValid()) {
// Perform the transition
def issueResult = issueService.transition(user, validationResult)
}
}else
{
return("<p style=color:green>VALID</p>"
}
Shivaprasad Hattaraki
Contributor
June 20, 2018

 have tried but not working.

I have tried with script listener but not working.

Suhas P
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.
June 20, 2018

Its syntax errors I guess. have you tried adding those missing brackets { s? I have updated now. 

Shivaprasad Hattaraki
Contributor
June 20, 2018

yaa i have tried with adding  those brackets { but not working.

Shivaprasad Hattaraki
Contributor
June 20, 2018
import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager

def warrantyField = customFieldManager.getCustomFieldObjectByName("Valid Warranty Date")

def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()

return warranty > systemDate

Could you make transition for this?

Value returns true or false boolean values.

 

if it returns true the transition validate date(21) action id has to perform else invalidate(31) action id has to perform. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events