Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Changing filter owner with groovy

Hello all, 

I am trying to change the owner of a filter, but I'm not being successful. Any idea why? Any validations that I need to do? Omitted all the imports for clarity. 

def decomUser= userManager.getUserByName("vescalante")
def targetUser = userManager.getUserByName("gcheung")
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Reassign all filters
SearchRequestService searchRequestService = ComponentAccessor.getComponent(SearchRequestService.class)
def contextImpl = new JiraServiceContextImpl(decomUser)

Collection<SearchRequest> searchRequests = searchRequestService.getOwnedFilters(decomUser)

if(searchRequests.size() > 0) {
searchRequests.each { s ->
s.setOwner(targetUser)
searchRequestService.updateFilter(contextImpl, s)
}
} else {
commentText << "\n\n (/) User *_${decomUser.getName()}_* doesn't own any filters, no reassignment required."
}
log.warn(commentText)

2 answers

1 accepted

Got it. I had to validate the change. 

searchRequestService.validateFilterForChangeOwner(jiraServiceContextImpl, s)
if (jiraServiceContextImpl.errorCollection.hasAnyErrors()){
        log.error(iraServiceContextImpl.getErrorCollection())
}
else{
       s.setOwner(targetUser)
       searchRequestService.updateFilterOwner(jiraServiceContextImpl, loggedInUser, s)
}

 

Hi Vivian,

Can you please share the full script again?

Thanks in advanced,
Maitrey

2 votes

Hey @Vivian Escalante

What version of ScriptRunner do you have? I believe you can do this with the built-in scripts Change dashboard or filter ownership. To get to the built-in scripts area you'll need to go to Add-ons > ScriptRunner > Built-in Scripts. Hope this helps! 

See below images. 

Screen Shot 2018-05-03 at 3.21.51 PM.png

Screen Shot 2018-05-03 at 3.22.03 PM.png

I'm trying to do this through a groovy script, but thank you. I'm aware this exists. I was able to figure it out! 

Just to throw out why the built-in script approach didn't work for me: it uses a user lookup for the From user field. If this was a free text box, it'd be better, but because it looks up usernames and only accepts a "valid" user, the built-in script is pretty useless when working with deactivated/deleted accounts.

Like # people like this

Hi @Vivian Escalante , did you get this to work with private filters? I get it to work if I share it before running the script but when its private I get this:

The filter is not shared with anyone. You cannot change the owner of private filters.

I know this is a old thread but I have been looking around and this was so close to what I need that I give it a go.

 

br Ole

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

235 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you