Forums

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

Scriptrunner : groovy, trying to use SwimlaneService and Swimlane

Olivier Billaud
Contributor
July 22, 2022

Hello dear friends, 

 

I'm stuck on groovy development about boards (rapid views), and more precisely on swimlanes.

I'm trying to add programmatically a new swimlane in my board.

For this, I found these classes:

https://docs.atlassian.com/jira-software/6.7.7/com/atlassian/greenhopper/service/rapid/view/SwimlaneServiceImpl.html

- https://docs.atlassian.com/jira-software/6.7.6/com/atlassian/greenhopper/model/rapid/Swimlane.SwimlaneBuilder.html

https://docs.atlassian.com/jira-software/6.7.7/com/atlassian/greenhopper/service/rapid/view/RapidViewServiceImpl.html

 

Here is my current code (it doesn't work at all):

import com.atlassian.greenhopper.model.rapid.RapidView
import com.atlassian.greenhopper.model.rapid.Swimlane
import com.atlassian.greenhopper.model.rapid.Swimlane.SwimlaneBuilder
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.rapid.view.SwimlaneService
import com.atlassian.greenhopper.service.rapid.view.SwimlaneServiceImpl
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean


@JiraAgileBean

RapidViewService rapidViewService

def authenticationContext = ComponentAccessor.jiraAuthenticationContext
def user = authenticationContext.loggedInUser

def view = rapidViewService.getRapidView(user, 11014).get() // ID of board - you can see that in the URL

def swimlaneService = new SwimlaneServiceImpl()
log.debug swimlaneService;
log.debug view

allSwims = swimlaneService.loadSwimlanes(view)

for (swim in allSwims){
    log.debug swim.toString()
}

def newSwimBuilder = new SwimlaneBuilder()
newSwimBuilder.name("New swimlane")
newSwimBuilder.query("'parent link' = KEY-1")
newSwimBuilder.position(2 as Integer)
def newSwim = newSwimBuilder.build()

log.debug newSwim.getId()
log.debug newSwim.getName()
log.debug newSwim.getQuery()
log.debug newSwim.getPosition()

swimlaneService.add(user, view, newSwim)

 

Honestly, ... 

1. I found how to instantiate "rapidViewService" and it works, but I don't even understand how and why, first time I see this "@JiraAgileBean"... But nevermind. It works. But if you have time to explain to me what is this...

2. With SwimlaneService, I have the following error, after trying to access all swimlanes (loadSwimlanes(RapidView)) and I don't know why:

2022-07-22 16:11:20,224 ERROR [common.UserScriptEndpoint]: Script console script failed: java.lang.NullPointerException at com.atlassian.greenhopper.service.rapid.view.SwimlaneServiceImpl.loadSwimlanes(SwimlaneServiceImpl.java:84)

3. I found the "SwimlaneBuilder" and i can populate some fields (name, query...) but I don't know how to save it (and then, how to have a valid id for this new swimlane).

 

I'm pretty far from my goal. 

Please, help me if you can!

Thank you so much <3 love on you.

Oliv'

 

1 answer

1 accepted

1 vote
Answer accepted
Tarun Sapra
Community Champion
August 24, 2017

To implement this functionality you would need to do some coding and write your own plugin.

An alternate is to create a loop-back transition called "create sub-task" which return the user to the same status and when a user clicks on the transition button then in the workflow post-function a sub-task is created.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events