Jira Transition Query

Harsh
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, 2023

Is it possible to hide a transition if another transition is not triggered once.

Scenario is I have 2 outgoing transition from a status In Progress(T1 and T2), I want to hide T1 until T2 is triggered once. If T2 is triggered one time then, unhide T1.

Is this achievable by condition/custom script, any help would be appreciated.


2 answers

1 accepted

0 votes
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2023

Hi @Harsh 

I am not sure if this can be achieved through checking specified transition, but I can propose a solution that checks status changes.

You can examine the previous and new status names in the issue change history. If they match, you can return a boolean "true."

Here's some sample code to get you started:

import com.atlassian.jira.issue.changehistory.ChangeHistory;
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;

List<ChangeHistory> changeItems = changeHistoryManager.getChangeHistories(genericIssue);

// check backwards if the status has been changed to from prevStatusName to nextStatusName
String prevStatusName = "status-before-transition"
String nextStatusName = "status-after-transition"
for
(int i = changeItems.size() - 1; i >= 0; --i) {
ChangeHistory changeItem = changeItems.get(i);

List<GenericValue> changes = changeItem.getChangeItems();
Iterator<GenericValue> it = changes.iterator();

while (it.hasNext()) {
GenericValue change = it.next();
String changedField = change.getString("field");

if (changedField.equalsIgnoreCase("status")) {
String oldStatus = change.getString("oldstring");
String newStatus = change.getString("newstring");

if (prevStatusName.equals(oldStatus) && nextStatusName.equals(newStatus)) {
return true;
}
}
}
return false;
}
Harsh
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, 2023

Hi @Tuncay Senturk 

Thanks for the reply I will try that.


Until the let me elaborate. 


I have status In Progress which has 2 transition T1 and T2. T1 is a self loop to 'In Progress' and T2 goes to END.

When the status is IN PROGRES, I do not want to see T2 until T1 is executed. T1 acts an approval factor.

I Hope this is understandable.


Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2023

I see, the previous and next status names are In Progress. I'm afraid this is the worst case for this scenario because Jira API does not provide which transition changed the status.

Harsh
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, 2023

Yes. 

Harsh
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, 2023

Can we modify the code which I send in the comment below and modify? 

I tried all posible scenario but it doesn't work. 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2023

are you sure that there is a property like transition1.count ?

I checked the API here but I could not find that property/getter.

Harsh
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, 2023

I did find that in a community so tried code with that. Not sure where was it. Have been trying since a long time. 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2023

And I believe that transitionmanager provides the definition of the workflow transitions, not the historical values for the issues.

Harsh
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, 2023

Oh. 

Yes I believe I'm using that to get the transition name. And then comparing. 

 

I belive the code which I tried is not valid at all. 

0 votes
Mohamed Adel
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, 2023
Harsh
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, 2023

Hi @[deleted] 

Yes I did try, but unfortunately it is what I want. 

 

I want that T1 should be hidden until T2 is executed once. If T2 is triggered once, then unhide T1. 

I tried the below code but no luck

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.workflow.WorkflowTransitionUtil

import com.opensymphony.workflow.WorkflowContext

 

// Define the issue and workflow context

Issue issue = issue

WorkflowContext context = WorkflowTransitionUtil.getWorkflowContext(issue)

// Get the list of transitions for this issue

def transitionManager = ComponentAccessor.getWorkflowTransitionManager()

def transitions = transitionManager.getAvailableActions(issue, context)

 

// Find the "Transition 1" and "Transition 2" transitions

def transition1 = transitions.find { it.name == "Transition 1" }

def transition2 = transitions.find { it.name == "Transition 2" }

// Check if "Transition 1" has been executed once

if (transition1 && transition1.count > 0) {

    // "Transition 1" has been executed, so unhide "Transition 2"

    return true

} else {

    // "Transition 1" has not be

en executed, so hide "Transition 2"

    return false

}.

 But no luck

Mohamed Adel
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, 2023

Hi @Harsh  

let me explain the solution:

  • Create a customField with default value "0"
  • Make T2 hidden based customField value != 0
  • on T1 transition add a post function or automation rule or any simple scrip-trunner script to update the custom-field to be 1 


This should fix your issue I guess 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2023

This solution is very simple and straightforward, but it will not address the issues that have already undergone the transition.

Harsh
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, 2023

@Tuncay Senturk yes you are right. 

We do not any custom field to be added. 

Suggest an answer

Log in or Sign up to answer