Hey,
We have some criteria for Filters to be deleted in our Jira Instance.
Could anyone help with Script in Scriptrunner for below?
We need to create a script that delete filters which fall under these criteria:
or any idea is welcome.
Regards,
Anuradha
That is a pretty big ask.
I would start by reviewing this post
Jira questions Bulk-Delete-Issues-Using-ScriptRunner
Work on a base from there and many of us can help beyond that.
Hi @CJ Edwards ,
Thanks but the post you gave is for issues right? not for Filters.
I tried below Script:
But seeing some errors. Could you please help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anuradha,
I would work from the top of the script to narrow the problems.
- getAllUsers() was deprecated long ago. Use UserSearchService.findUsers() use https://docs.atlassian.com/software/jira/docs/api/9.8.1/com/atlassian/jira/bc/user/search/UserSearchService.html
- for filter work use - com.atlassian.jira.bc.filter - Interface SearchRequestService
The error listed in your picture is from passing DelegatingApplicationUser instead of ApplicationUser that the function is expecting.
I hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi folks
I have realized a similare case by using the following console script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.issue.search.SearchRequestManager
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
Logger logger = Logger.getLogger("script.console")
/*
* This script removes shared filters using a list of filter ids (as long).
*/
//
// Define the 'manager(s)' before we can de configuration (!)
SearchRequestManager searchRequestManager = ComponentAccessor.getComponent( SearchRequestManager )
//
// Configuration: Define an array of all 'shared filter ids' which should be deleted.
long[] sharedFilterIDs = [17638, 18168, 18509, 18623]
// Remove all 'shared filters' if they does exist.
sharedFilterIDs.each { long sharedFilterID ->
SearchRequest sharedFilter = searchRequestManager.getSearchRequestById( sharedFilterID )
if ( sharedFilter != null ) {
// Delete the 'shared filter'
logger.debug "The filter '${sharedFilter.getName()}' (${sharedFilter.getId()}) owned by '${sharedFilter.getOwner().getDisplayName()}' is deleted."
searchRequestManager.delete( sharedFilterID )
// Now we check if the 'shared filter' has really been deleted.
if ( searchRequestManager.getSearchRequestById( sharedFilterID ) != null ) {
logger.error "The filter '${sharedFilter.getName()}' (${sharedFilter.getId()}) owned by '${sharedFilter.getOwner().getDisplayName()}' was not deleted!"
}
} else {
logger.error "The filter with the id ${sharedFilterID} does no more exist!"
}
}
logger.info "All shared filters (${sharedFilterIDs.size()}) are deleted."
Hope it helps you.
Regards, Rolf
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you have success using ScriptRunner to bulk delete filters?
I'm working on a project where I need to delete all the inactive users's filters or delete them by their filter id.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.