scriptrunner post function to add watchers based on component

Hemant S August 4, 2016

I am trying to write a post function using script runner to add watchers to the issue when created depending on components. 

I was able to get the watchers to be added but i am not able to get a condition check with component working. How do i get a list of components for the issue and then define a user list to be added as watchers.

5 answers

1 vote
Darren Weaver December 20, 2016

Apologies, my scripting capabilities are somewhat limited.  I took a look at the link but I'm not sure it suits the use case.  Upon issue creation (post function) I need a watcher to be automatically added based on a component selected.  I couldn't find that information in the link.  sad

0 votes
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.
December 18, 2016
Henry Lin August 24, 2020

hi @JamieA , thanks for the sharing the sample! the sample is for adding the component's lead to the Watchers (field), is there a sample for adding component watcher/s to the Watchers in the ticket (when the component is selected)? For ex: Component A has watcher1 and watcher2, when Component A is selected, both of watcher1 and watcher2 are added to Watchers field. 

Henry Lin September 9, 2020

hi @Martin Bayer _MoroSystems_ s_r_o__ , any thoughts on this request? appreciate your input! 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2020

hi @Henry Lin what do you mean by "component watchers"?

Henry Lin September 10, 2020

hi @Martin Bayer _MoroSystems_ s_r_o__ , sorry, I wasn't cleared about it, I was referring to this plugin Component Watcher for Jira.

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 10, 2020

@Henry Lin I was not aware of this App, but I'm checking its source code and documentation 

It looks like there is no public Java API, but there is public REST API. I can see, there are two endpoints which accept "project key" as a parameter

  • /rest/componentwatchers/1.0/groups/{projectkey}

  • /rest/componentwatchers/1.0/users/{projectkey}

Response of both endpoints contains this "section" of data

{
    "projectKey": "TST",
    "projectName": "Test",
    "component": "Design",
    "watchers": []
  }

watchers will containt data you need. There will be user's identifiers when using "/users/" endpoint and group's identifiers for "/groups/" endpoint

For users

You can use https://docs.atlassian.com/software/jira/docs/api/7.6.1/index.html?com/atlassian/jira/user/util/UserManager.html to get the ApplicationUser based on the key

For groups

You need to get group members using https://docs.atlassian.com/software/jira/docs/api/7.6.1/index.html?com/atlassian/jira/security/groups/GroupManager.html and method 

Collection<ApplicationUser> getUsersInGroup(String groupName)

 

Then you have collection of all users configured as component watchers which can be used in script posted by @JamieA  to add users to watchers.

Henry Lin September 12, 2020

hi @Martin Bayer _MoroSystems_ s_r_o__ , thanks for the info! 

0 votes
Darren Weaver December 15, 2016

@Jamie Echlin [Adaptavist], can you help with this? I'm just trying to get the script to run for adding watchers upon issue create. 

0 votes
Darren Weaver December 15, 2016

Hi Hermant, I'm trying to do the same thing- can you share the script you used to add watchers upon create issue?

 

0 votes
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.
August 7, 2016

For example the following would be true if there is a component call Foo selected:

"Foo" in issue.getComponents()*.name

Suggest an answer

Log in or Sign up to answer