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.
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;
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can we modify the code which I send in the comment below and modify?
I tried all posible scenario but it doesn't work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
are you sure that there is a property like transition1.count ?
I checked the API here but I could not find that property/getter.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did find that in a community so tried code with that. Not sure where was it. Have been trying since a long time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And I believe that transitionmanager provides the definition of the workflow transitions, not the historical values for the issues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Harsh
Did you try that answer https://community.atlassian.com/t5/Jira-questions/Hide-transition-based-on-other-transition/qaq-p/899150
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Harsh
let me explain the solution:
This should fix your issue I guess
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This solution is very simple and straightforward, but it will not address the issues that have already undergone the transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tuncay Senturk yes you are right.
We do not any custom field to be added.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.