You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Need groovy script to run from Jira script runner to update the filters:
Fetch all the JQL filters based on issue type which is equal to "xyz",
then exclude the ones with issue type "Profile xyz", then update the filters with issue type as "feature".
Hi @Meghana K V
Could you provide a little bit more information, i.e. what Automation function are you using for this? Is the Issue Create or Transition Issue?
It would be beneficial if you could share a screenshot of your Automation configuration.
I am requesting this so I can provide a sample script.
Thank you and Kind regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Thank you for your reply.
I have created the following script for the requirement mentioned above, but it's not working, please let me know what I am missing.
I have to fetch all the filters with issuetype = EPIC and exclude the ones with issuetype = Portfolio EPIC and then to the resulting filters, I need to change the issuetype to Feature.
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.bc.JiraServiceContextImpl
import java.lang.StringBuffer
SearchRequestService searchRequestService = ComponentAccessor.getComponent(SearchRequestService.class)
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService)
SearchService searchService = ComponentAccessor.getComponent(SearchService)
def sb = new StringBuffer()
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def ctx = new JiraServiceContextImpl(loggedInUser)
UserSearchParams userSearchParams = new UserSearchParams.Builder()
.allowEmptyQuery(true)
.includeInactive(false)
.ignorePermissionCheck(true)
.maxResults(5000)
.build()
// Define the issue type name to search for
def issueTypeName = "EPIC"
def excludedIssueTypeName = "Portfolio EPIC" // Add the excluded issue type name here
def newissueTypeName = "Feature"
println "Starting script execution"
// Iterate over each user's filters
userSearchService.findUsers("", userSearchParams).each { ApplicationUser filter_owner ->
try {
searchRequestService.getOwnedFilters(filter_owner).each { SearchRequest ->
def query = SearchRequest.query
def queryString = searchService.getJqlString(query)
println("Old Filter '$queryString' updated successfully.")
if (queryString.contains(issueTypeName) && !queryString.contains(excludedIssueTypeName)) {
String newQueryString = queryString.replace(issueTypeName, newissueTypeName)
def newQuery = searchService.parseQuery(filter_owner, newQueryString).query
sb.append("Filter for ${filter_owner.displayName}: ${query.name}, ${query.getPermissions().isPrivate() ? 'Private' : 'Shared'}\n")
SearchRequest.setQuery(newQuery)
searchRequestService.updateFilter(ctx, SearchRequest)
}
}
}catch (Exception e) {
// If filter is private or encounters an error
sb.append("Unable to get filters for ${filter_owner.displayName} due to ${e}\n")
}
}
// Output results
return sb.toString()
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.