How to do it...

Go through the following steps to run a custom Groovy script in Jira (note that you will need to update the filter IDs accordingly):

  1. Navigate to Administration > Manage apps > Script Console.
  2. Copy the following script into the Script text area:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.favourites.FavouritesManager
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.issue.search.SearchRequestManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.exception.PermissionException

//Set the filter ID and group to share with here
Long[] searchRequestIds = [10302,10303,10304]
String shareWith = "jira-software-users"
FavouritesManager favouritesManager = ComponentAccessor.getComponent(FavouritesManager.class)
SearchRequestManager searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager.class)
UserManager userManager = ComponentAccessor.getComponent(UserManager.class)
GroupManager groupManager = ComponentAccessor.getComponent(GroupManager.class)

for(Long searchRequestId in searchRequestIds) {
SearchRequest searchRequest = searchRequestManager.getSharedEntity(searchRequestId)

for (String userName in groupManager.getUserNamesInGroup(shareWith)) {
try {
favouritesManager.addFavourite(userManager.getUserByName(userName), searchRequest)
} catch (PermissionException e) {
// the user does not have permission to view this filter
}
}
}
  1. Switch the filter IDs (searchRequestIds) and group name (shareWith) based on your data. You can get filter IDs by running your filter, and the ID will be in your browser's address bar.
  1. Click on Run to execute the script.

The Script Console window is shown in the following screenshot:

You can see the information being displayed in the console.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.63.165