Forums

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

How to create Conditional transition screen?

Kedar Kanel
Contributor
February 22, 2024

I have a global transition named "2 Resolve".  I also have screen named "Resolved Screen".

How can I create Workflow Condition such that transition screen (Resolved Screen) is visible during "2 Resolve" only if the the condition is true. 

2 answers

0 votes
Judah
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.
February 26, 2024

@Kedar Kanel - Here is a related article that helped me when I was attempting to show a transition screen conditionally based on a custom field value...this got me where I needed to be.

I hope it helps you! 

 

https://community.atlassian.com/t5/Jira-Software-questions/Show-transition-screen-conditionally-based-on-field-value-in/qaq-p/686294

0 votes
Emily _ DevSamurai
Community Champion
February 22, 2024

Hi @Kedar Kanel 

To create a conditional transition screen in Jira, you'll need to configure conditions in your workflow. Conditions in Jira workflows control whether a transition should be available to a user based on specified criteria. Here are some Atlassian documents for your reference:

I hope this will help.

Kedar Kanel
Contributor
February 22, 2024

Hi @Emily _ DevSamurai yes Conditions in Jira workflow control whether a transition should be available to user or not.

I want the transition to be visible all the time but only trigger the Transition Screen if certain condition is met. 

Is it possible to set/remove screen to workflow transition using script? That would also solve the problem. Then I could create Scriptrunner Behaviour and set or remove screen to the required workflow transition.

Kristian Walker _Adaptavist_
Community Champion
February 23, 2024

Hi Kedar,

Having the transition screen dynamically set for certain issue types in the same transition by a script is impossible, as Atlassian does not provide any Rest APIs to do this. 

Regards,

Kristian

Kedar Kanel
Contributor
February 23, 2024

Hi Kristian,

How about

from 

  • com.atlassian.jira.bc.workflow.DefaultWorkflowTransitionService

How is it used? When I tried to use it I got following error

groovy.lang.MissingMethodException: 
No signature of method: static com.atlassian.jira.bc.workflow.DefaultWorkflowTransitionService.setScreen() is
applicable for argument types: (String, com.atlassian.jira.issue.fields.screen.FieldScreenImpl...)
values: [testTransition, [FieldScreenImpl Test Screen], com.atlassian.jira.workflow.ConfigurableJiraWorkflow@5512a465]
Possible solutions: setScreen(java.lang.String, com.atlassian.jira.issue.fields.screen.FieldScreen, com.atlassian.jira.workflow.JiraWorkflow)

Here is my code


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.workflow.WorkflowManager
import com.opensymphony.workflow.loader.ActionDescriptor

import com.atlassian.jira.bc.workflow.DefaultWorkflowTransitionService

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.screen.FieldScreen
import com.atlassian.jira.issue.fields.screen.FieldScreenManager

WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
def workflow = workflowManager.getWorkflow(issue);
String workflowName = workflow.getName();
log.warn("Workflow name: " + workflowName);

def wfd = workflow.getDescriptor();
log.warn("Current action name: $wfd");

def allactions = workflow.getAllActions()
log.warn("All actions ID and names" + allactions.collect {it.name+ ' '+ it.id})

def actionName = wfd.getAction(31).getName(); // Replace with actual workflow transition ID
log.warn("Current action name: $actionName");

def fieldScreenId = 10100 // Replace with the actual field screen ID
FieldScreenManager fieldScreenManager = ComponentAccessor.getFieldScreenManager()
FieldScreen fieldScreen = fieldScreenManager.getFieldScreen(11600) // Replace with actual screen ID
log.warn("Field screen is $fieldScreen")
log.warn("Field screen is " + fieldScreen.getId())

def setScreen = DefaultWorkflowTransitionService.setScreen(actionName, fieldScreen ,workflow)
log.warn("success")

I also tried actionDescriptor.setView(fieldScreenId.toString()) which got executed without error but it broke the workflow. 

Below is the code for it

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.screen.FieldScreen
import com.atlassian.jira.issue.fields.screen.FieldScreenManager
import com.atlassian.jira.workflow.WorkflowManager
import com.opensymphony.workflow.loader.ActionDescriptor

WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager()
def workflow = workflowManager.getWorkflow(issue)
String workflowName = workflow.getName()
log.warn("Workflow name: " + workflowName)

def wfd = workflow.getDescriptor()
log.warn("Current action name: $wfd")

def allActions = workflow.getAllActions()
log.warn("All actions ID and names" + allActions.collect { it.name + ' ' + it.id })

def actionName = wfd.getAction(31).getName() // Replace with actual workflow transition ID
log.warn("Current action name: $actionName")

def fieldScreenId = 11600 // Replace with the actual field screen ID
FieldScreenManager fieldScreenManager = ComponentAccessor.getFieldScreenManager()
FieldScreen fieldScreen = fieldScreenManager.getFieldScreen(11600) // Replace with actual screen ID
log.warn("Field screen is $fieldScreen")
log.warn("Field screen is " + fieldScreen.getId())

// Use ActionDescriptor to set the screen association
def actionDescriptor = wfd.getAction(31) as ActionDescriptor // Replace with actual workflow transition ID
actionDescriptor.setView(fieldScreenId.toString())
log.warn("Success")

 

Kristian Walker _Adaptavist_
Community Champion
February 25, 2024

Hi Kedar 

These Apis are for Jira dat center / server and will work on this but if on cloud they will not work.

I was not aware of these data center apis myself so thank you for suggesting these.

Regards,

Kristian 

Suggest an answer

Log in or Sign up to answer