Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jechlin-adaptavist/cbc9ec28b9d47ebf8e13184ce7ee610e to your computer and use it in GitHub Desktop.
Save jechlin-adaptavist/cbc9ec28b9d47ebf8e13184ce7ee610e to your computer and use it in GitHub Desktop.
import com.atlassian.greenhopper.model.rapid.RapidView
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
@JiraAgileBean
RapidViewService rapidViewService
def authenticationContext = ComponentAccessor.jiraAuthenticationContext
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchRequestService = ComponentAccessor.getComponent(SearchRequestService)
def user = authenticationContext.loggedInUser
def view = rapidViewService.getRapidView(user, 1).get() // ID of board - you can see that in the URL
def updatedView = RapidView.builder(view).name('Some new name').build()
def filterId = updatedView.savedFilterId
def serviceContext = new JiraServiceContextImpl(user)
def filter = searchRequestService.getFilter(serviceContext, filterId)
def updatedFilter = new SearchRequest(filter)
def newQuery = jqlQueryParser.parseQuery('project = JRA ORDER BY Rank ASC') // new filter
updatedFilter.setQuery(newQuery)
searchRequestService.updateFilter(serviceContext, updatedFilter)
rapidViewService.update(user, updatedView)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment