You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
I'm trying to bulk update the security level of a project (more than 10k issues hence not using the in house bulk update functionality). This is my script. I can't seem to set the security level.
What returns are all the issues in the JQL but can't seem to set the security level. Anyone has any ideas?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.MutableIssue
// Issues returned from that JQL will get altered
final searchQuery = "project in ('TEST") and level is EMPTY"
// Get some components
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// Perform the JQL search
def query = jqlQueryParser.parseQuery(searchQuery)
def results = searchProvider.search(query, user, PagerFilter.unlimitedFilter)
// Iterate all results to update each issue
results.issues.each {
def issue = issueManager.getIssueObject(it.id)
issue.setSecurityLevelId(12769)
}
Hi @Filzah Aziz
I think the main problem is, that you are setting security level id, but you are not updating the issues.
Please, try something like this:
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
Long securityLevelId = 12769
String query = 'project in ("TEST") and level is EMPTY'
IssueManager issueManager = ComponentAccessor.getIssueManager()
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Query searchQuery = jqlQueryParser.parseQuery(query)
SearchResults<Issue> results = searchService.search(user, searchQuery, PagerFilter.getUnlimitedFilter())
List<Issue> foundIssues = results.getResults()
foundIssues.each { Issue foundIssue ->
MutableIssue issue = issueManager.getIssueObject(foundIssue.getId())
issue.setSecurityLevelId(securityLevelId)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
I didn't test it, so please, be careful and do some tests on smaller amount of issues. Maybe you will also need to perform the reindex after bulk update.
@Hana Kučerová Thanks for taking the time to answer my question. I see what you mean. I tried using your script however there is an error:
It is saying that the class com.atlassian.jira.issue.search.SearchResults takes no parameters.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Filzah Aziz The previous code should work in newer versions, searchService and results changed in time, so please try to replace:
SearchResults<Issue> results = searchService.search(user, searchQuery, PagerFilter.getUnlimitedFilter())
List<Issue> foundIssues = results.getResults()
with
SearchResults results = searchService.search(user, searchQuery, PagerFilter.getUnlimitedFilter())
List<Issue> foundIssues = results.getIssues()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works- thank you for helping. And definitely need to do a reindex right after!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Filzah Aziz
glad to help :-).
Would you please mark my answer as accepted? This action will mark the question as resolved and it can also help other users in the future to find the solution, if they have similar problem. Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.