Forums

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

Setting transition property during post function

Joel Batac
Contributor
August 28, 2022

Is it possible to set a transition's property in particular opsbar-sequence property in post function?

1 answer

0 votes
Ivan Lima
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.
August 28, 2022

Hi @Joel Batac, I haven't tried it myself, but I believe there is a way you can do that. I googled around and came across similar posts that might help you to get more insights into this. Also, if you can provide more details of your use case, we might be able to come up with alternative solutions and suggestions if applicable.

Joel Batac
Contributor
August 28, 2022

HI Ivan, thanks for the response.  

Basically I have a workflow (pls see attached image), where from New status it can transition to any of 4 statuses -Research and Analysis, Architecture Assessment, Pending Review and Ready to Refine.  And all those those 4 statuses can transition to each other as well as go back to New.

My user what to see the transition button to follow  - 
New > Research and Analysis > Architecture Assessment > Pending Review > Ready to Refine.

I set the opsbar setting as :

Cancel = 10

Research and Analysis = 20

Architecture Assessment = 30

Pending Review = 40

Ready to Refine = 50

The first 2 times of transitioning are fine, - from New to Research and Analysis, from Research and Analysis to Architecture Assessment. But after the second transition, it shows Research and Analysis again, which is expected based on the opsbar setting. I want to show Pending Review instead.  And after this, Ready to Refine.

How can this be achieve?

 

first transition.pngsecond transition.pngthird transition.pngworkflow.PNG

Ivan Lima
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.
August 28, 2022

Before we get into this rabbit hole, which version are you in and what are the plans to upgrade to Jira 9.x version? I'm saying it because the issue status and transitions have a different look and feel from Jira 9 onward, and the effort you're putting into this may not make sense once you upgrade. I'm trying to help you understand whether the juice is worth the squeeze in your case.

Joel Batac
Contributor
August 28, 2022

we're using version 8.20.8

Ivan Lima
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.
August 29, 2022

Right. Did you check the link I shared with the new view for issue status and transition? Do you know when you're instance will get upgraded to 9.x?

Now, back to your implementation, did you try to put a code together based on the references I shared initially? I can try to carve out some time this week to attempt this if nobody else chimes in here.

Joel Batac
Contributor
August 29, 2022

Hi Ivan,

 I tested the script in post function to set Research and Analysis transition opsbar setting  from 10 to 60 but got the ff: 

java.lang.IllegalArgumentException
at com.atlassian.jira.workflow.AbstractJiraWorkflow.getLinkedStep(AbstractJiraWorkflow.java:204)
at com.atlassian.jira.workflow.JiraWorkflow$getLinkedStep.call(Unknown Source)
at Script24.run(Script24.groovy:9)

 

 

import com.atlassian.jira.component.ComponentAccessor

Map attributes = new HashMap()
attributes.put("opsbar-sequence","60")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def workFlowManager = ComponentAccessor.getWorkflowManager()
def workflow = workFlowManager.getWorkflow("Standard Template Initiative Workflow")
def status = ComponentAccessor.getConstantsManager().getStatus("Research and Analysis")   /// this is line #9
def stepDescriptor = workflow.getLinkedStep(status)
stepDescriptor.setMetaAttributes(attributes)
workFlowManager.updateWorkflow(user, workflow)

Ivan Lima
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.
August 29, 2022

The code above didn't work for me either. Therefore, I put this one together and tested it with a simple workflow, which worked. Give it a try. I suggest you try it in the script console before diving into your logic so you can confirm it's working as expected.

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

def workflowManager = ComponentAccessor.getWorkflowManager()
def workflow = workflowManager.getWorkflow("YOUR WORKFLOW NAME")

Collection<ActionDescriptor> actionToDo = workflow.getActionsByName("To Do")
Collection<ActionDescriptor> actionInProgress = workflow.getActionsByName("In Progress")
Collection<ActionDescriptor> actionDone = workflow.getActionsByName("Done")

Map<string, string> map1 = new HashMap()
map1.put("opsbar-sequence", "10")
actionToDo[0].setMetaAttributes(map1)

Map<string, string> map2 = new HashMap()
map2.put("opsbar-sequence", "20")
actionInProgress[0].setMetaAttributes(map2)

Map<string, string> map3 = new HashMap()
map3.put("opsbar-sequence", "30")
actionDone[0].setMetaAttributes(map3)
Joel Batac
Contributor
August 30, 2022

cool..thanks for this. Although i found a workaround before seeing this, still appreciated the help.

 

Workaround was to update the XML and rearrange the 'common-action id' entries for each steps - putting the first transition at the top.

 

Sample

<step id="4" name="Architecture Assessment">
<meta name="jira.status.id">43200</meta>
<actions>
<common-action id="391" />  #### Pending Review transition
<common-action id="401" />
<common-action id="381" />
<common-action id="411" />

Ivan Lima
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.
August 30, 2022

I'm glad you found a workaround, but I suppose you're not setting it during a post-function nor using scriptrunner, are you?

Joel Batac
Contributor
September 1, 2022

That's right. Basically hard coded.  The only requirement from user is to have the next transition next to Cancel 

Suggest an answer

Log in or Sign up to answer