Hi, (especially @Kristian Walker _Adaptavist_ )
I am trying to create a custom listener that would add a specific user group, let's call it "INV" on a specific event.
The most similar use case I found is adding a project role as watchers.
I can't script this, could someone help me adjust the script to use a specific group?
Thanks a lot in advance,
Daniel
Here is the script from the other post, modified to get group members instead of project role members, I haven't actually tried it. But it should work.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.security.roles.ProjectRoleManager Issue issue = event.issue def watcherManager = ComponentAccessor.getWatcherManager() def userUtil = ComponentAccessor.userUtil userUtil.getAllUsersInGroupNames(['INV']).each {user -> watcherManager.startWatching(user, issue) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter, would it be possible to modify this to use it for users in a specific Project Role, as an "On Create" post function? I've been trying to get it to work for my use case but having a hard time as I am inexperienced. Thank you regardless.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Matthew Frassetti that's what was in the post linked by the OP: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Add-Project-roles-as-watchers-in-issue/qaq-p/265512
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan
The above script is also adding Inactive users as a watcher. How I can exclude the inactive users?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This has gotten a lot simpler with HAPI.
The same result can be achieved with
Groups.getByName('INV').members.findAll{it.active}.each{
event.issue.addWatcher(it)
}
No imports needed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @PD Sheehan One last thing - I want to add the condition based on the Issue Type & field value. currently, it applies on whole project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add something at the top to exit if the condition is not met.
if(event.issue.issueType.name != 'your issue type') return
if(event.issue.getCustomerFieldValue('some field') != 'your value') return
//conditions have been met, continue with adding watchers
Groups.getByName('INV').members.findAll{it.active}.each{
event.issue.addWatcher(it)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
I have tested the code provided by Peter in the response above using the latest version of ScriptRunner and Jira 7.13.1 and can confirm this code worked when I configured as a script listener on the issue updated event.
The code added all users in the INV group as watchers on an issue when it is updated and I would advise using the code provided by Peter to achieve your requirement ensuring you set it to run on the event that you require.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for testing Kristian, indeed it worked for me :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.