Request working script to favorite issue on behalf of all users

Samir Freelance
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2011

Can somebody give me a working script so i can run using script runner (Groovy)

in order to add all my saved filter for users Distribution automatically subscribe filters on behalf of users ?

thanks

1 answer

1 accepted

2 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2011

OK, I submit. Here is the script. As someone said before you need to use a group not a username (eg carla).

Please please please close or mark correct your previous questions. If you enter lots of similar questions you are merely making it very difficult for people to help you because they don't know which question to answer.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.favourites.FavouritesManager
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.issue.search.SearchRequestManager
import com.opensymphony.user.UserManager

// Set the filter ID and group to share with here
Long searchRequestId = 10151
String shareWith = "some group"

ComponentManager componentManager = ComponentManager.getInstance()
FavouritesManager favouritesManager = (FavouritesManager) componentManager.getComponentInstanceOfType(FavouritesManager.class)
SearchRequestManager searchRequestManager = componentManager.getSearchRequestManager()
SearchRequest searchRequest = searchRequestManager.getSharedEntity(searchRequestId)

UserManager userManager = UserManager.getInstance()
for (String userId in userManager.getGroup(shareWith).getUsers()) {
favouritesManager.addFavourite(userManager.getUser(userId), searchRequest)
}

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2011

Note that the filter needs to be shared, the script above just makes it a favourite. So share with somegroup, then run the script above with somegroup.

If you are having trouble with this perhaps you might be better off with a packaged plugin that doesn't require configuration.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2011

click on one of the filters in your screenshow, in the url it will show the filter ID.

Samir Freelance
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2011

from where do I get the the filter ID so I can put in

Long searchRequestId ?
Samir Freelance
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2011

Halleluyaaaaaaaaaaa thanks it is working for group )

you saved me from the deep sea )

I am gonna dance LA SAMBA

I need to update all my posts and questions and paste your script

thanks for your answer and your valuable time , I didn t give up I knew the solution is there !

Samir Freelance
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2011

Jamie is it possible to add several filter ID to the line

Long searchRequestId

this one is for a single filter id Long searchRequestId = 10300

but if i have 10301,10302 ,10303 what can i do

shouu i add them line by line?

Merci

Giovanni Melai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2018

Hi Jamie,

do you have this script updated for Jira 7?

Regards

Abhishek Deshpande October 23, 2020

Hi @JamieA , @Samir Freelance 

I tried using the script you provided here, but getting errors. Could you please help?

 

My Task : I have created a Filter, shared with a Group. Now I want to add this filter as a Favorite Filter to all the members of this Group.

 

Error1: Unable to resolve class

import com.opensymphony.user.UserManager

 

I tried using below as well but could not get through.

import com.atlassian.crowd.embedded.api.User;

 

It would be really helpful if you have a script for this.

Suggest an answer

Log in or Sign up to answer