Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,524
Community Members
 
Community Events
185
Community Groups

Update a board's Quick Filter in Jira using Groovy (ScriptRunner) - Jira Data Center

Edited

I have tried using the below code and got a NullPointerException error log. I've imported as many classes as I could find. Some even twice XD

Maybe I'm using the update function wrong or the ErrorCollection wrong. Any suggestions/solutions are greatly appreciated.

 

 

 

 

 

import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.parameters.annotation.*
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.rapid.view.QuickFilterService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.greenhopper.model.rapid.QuickFilter.QuickFilterBuilder
import com.atlassian.greenhopper.service.rapid.view.QuickFilterService.*
import com.atlassian.greenhopper.service.rapid.view.QuickFilterServiceImpl.*
import java.lang.String.*

import java.io.*
//import com.atlassian.jira.util.ErrorCollection
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.parameters.annotation.*
import com.atlassian.greenhopper.*
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.model.rapid.QuickFilter
import com.atlassian.greenhopper.service.rapid.view.*
import com.atlassian.greenhopper.service.rapid.view.QuickFilterService.*
import com.atlassian.greenhopper.service.rapid.view.QuickFilterServiceImpl.*
import com.atlassian.greenhopper.model.rapid.QuickFilter.QuickFilterBuilder
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.greenhopper.service.rapid.view.QuickFilterServiceImpl.update.*
import com.atlassian.greenhopper.model.validation.*
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.greenhopper.web.rapid.view.RapidViewHelper
import com.atlassian.greenhopper.service.rapid.view.QuickFilterServiceImpl


@WithPlugin("com.pyxis.greenhopper.jira")

@JiraAgileBean
RapidViewService rapidViewService


@JiraAgileBean
QuickFilterService quickFilterService

@JiraAgileBean
RapidViewHelper rapidViewHelper

def authenticationContext = ComponentAccessor.jiraAuthenticationContext
def applicationUserInput = authenticationContext.loggedInUser
QuickFilterServiceImpl quickFilterServiceImpl = new QuickFilterServiceImpl()
def errorCollection = new ErrorCollection()

def rapidViews = rapidViewService.getRapidView(applicationUserInput,1234).get()
def rapidViewsIn = quickFilterService.loadQuickFilters(rapidViews)
def quickFiltersIn = rapidViewsIn.query

def newQuickFilter = quickFiltersIn[3].replaceAll("To replace this JQL","This is now replaced").toString()

def newQuickFilterBuilder = new QuickFilterBuilder()
newQuickFilterBuilder.query(newQuickFilter)

def newQuickFilterBuild = newQuickFilterBuilder.build()



def update = quickFilterServiceImpl.update(applicationUserInput,rapidViews,newQuickFilterBuild,null)

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 28, 2023

Ah, a challenge :-)

Imports are not a problem - you'd get "can't find out how to do this" type errors.  Like "please multiply 6 by blue", the message would be "blue is not something any of our libraries know how to multiply by 6".  If your imports were wrong, you'd get "unrecognisable function" type messages.

NPEs are what Java throws when you try to say, "do this with a null/incomprehensible value", and the function can't cope.  (Don't blame the developers, they can't code for every possible NPE all the time, albeit I'm really bad at it)

So.  Your error report should be reporting the (first) line an NPE occurs.  One of the (not large numbers of) things I like about Java is that it reports the line of code it failed on, unlike the languages I learned to code in before 2004.

If you've got a 250-line script and you load it up in an editor that shows you line numbers, when you get an NPE reporting line 42, it really is happening on line 42, including all the empty lines you used to make it more readable.

So.  Can you tell us what line the NPE happens on?  Given your script posted above, what I would need to get started is a minimal "it happens on the line that says "XYZ"

The line that throws the NullPointerException (NPE) is:

def update = quickFilterServiceImpl.update(applicationUserInput,rapidViews,newQuickFilterBuild,null)
The log is: 
java.lang.NullPointerException at com.atlassian.greenhopper.service.rapid.view.QuickFilterServiceImpl.update(QuickFilterServiceImpl.java:145) at com.atlassian.greenhopper.service.rapid.view.QuickFilterService$update$0.call(Unknown Source) at Script490.run(Script490.groovy:68)
groovy:68 is line 65 of the code I shared in the description. 
Like Nic Brough -Adaptavist- likes this
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 29, 2023

Thanks!

So this is where you need to start working backwards - that update function needs broadly what you've named the variables you've put into it - the user to act as, the rapidview (board), a quickfilter, and an error collection object.

The user looks fine to me, so I'd start with the other three. 

The easiest one to amend would be the error collection - you've already created the object, but you've given the function null, so change it to the error collection instead.

If that doesn't work, or even just change the error message, then I'd look at the other two - one of them probably does not contain what the function needs.  

You could try to trace it back through the code, but you could do a much quicker and brutal test - try dumping the content of them in a simple log string "log.debug (rapidViews + "/" + newQuickFilterBuild)" 

Java will try to convert it to something moderately human-readable, but the obvious one is if you get a null in one, or both, you need to look at the code that is populating the variable.

Like Rinaldi James Michael likes this

I've narrowed down the source of the error. It's the errorCollection parameter. The only issue now is I do not know how to populate that. 

The errorCollection in use in the update function is from the Greenhopper library: https://docs.atlassian.com/jira-software/6.3.2.1/com/atlassian/greenhopper/model/validation/ErrorCollection.html

Unlike the errorCollection in https://docs.atlassian.com/software/jira/docs/api/7.4.1/com/atlassian/jira/util/ErrorCollection.html. The Greenhopper version has no known implementing classes. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events