It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Check if a transition is available from groovy script

Oded Priva Apr 28, 2014

I have this script to automaticly promote sub-tasks

Map doScript(Map params) {

        MutableIssue issue = params['issue'] as MutableIssue

        User currentUser = componentManager.getJiraAuthenticationContext().getUser()

        WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );

         

        SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();

        Collection<MutableIssue> subTasks = issue.getSubTaskObjects()

        if (subTaskManager.subTasksEnabled && !subTasks.empty) {

            subTasks.each {

                it ->

                log.debug ("issue.statusObject.name: " + issue.statusObject.name)

                workflowTransitionUtil.setIssue(it);

                workflowTransitionUtil.setUsername(currentUser.name);

                workflowTransitionUtil.setAction (761) 

         

                // validate and transition issue

                if (workflowTransitionUtil.validate()) {

                    log.debug("Ready To Start subtask " + it.key)

                    workflowTransitionUtil.progress();

                }

            }

        }

        return params

    }

How can I check if the transition 761 exists before using workflowTransitionUtil.setAction (761) ?

1 answer

1 accepted

1 vote
Answer accepted
Boris Georgiev Apr 28, 2014

Use:

def actionExists = com.atlassian.jira.component.ComponentAccessor.getWorkflowManager().getWorkflow(it).getDescriptor().getAction(761)  == null

Boris Georgiev Apr 28, 2014

You can also use com.atlassian.jira.workflow.IssueWorkflowManager.isValidAction(Issue, int)

Oded Priva Apr 29, 2014

Thanks Boris, I changes the code as you suggested

def actionId = 4 
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
        MutableIssue issue = issueManager.getIssueObject("ICTST-410");
        User currentUser = componentManager.getJiraAuthenticationContext().getUser()
        WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
        SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
        Collection<MutableIssue> subTasks = issue.getSubTaskObjects()
        if (subTaskManager.subTasksEnabled && !subTasks.empty) {
            subTasks.each {
                it ->
                log.debug ("issue.statusObject.name: " + issue.statusObject.name)
                if (com.atlassian.jira.workflow.IssueWorkflowManager.isValidAction(it, actionId)){
                     workflowTransitionUtil.setIssue(it);
                         workflowTransitionUtil.setUsername(currentUser.name);
                         workflowTransitionUtil.setAction (761) 
                         if (workflowTransitionUtil.validate()) {
                          workflowTransitionUtil.progress();

I tried using the code above but I'm getting the following error :

javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.workflow.IssueWorkflowManager.isValidAction() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, java.lang.Integer) values: [ICTST-411, 4]

I guess that the problem is that "it" is not IssueImpl .. how can I fix it?

Boris Georgiev Apr 29, 2014

you've got a mistake - You should use

com.atlassian.jira.component.ComponentAccessor.getComponent(com.atlassian.jira.workflow.IssueWorkflowManager.class).isValidAction(it,actionId)

Oded Priva Apr 29, 2014

Thanks Boris ... Thant did the trick.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

693 views 0 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you