Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

add reporter as watcher on JiraCloud

Hi everyone ! 

I need to add the original reporter as watcher on issue create. All of the guides that i found online are for scriptrunner for jira server, but i'm running a cloud instance and the scripts ( in scriptrunner.. ) doesn´t run.

is there any way to do this??


Thanks!

 

5 answers

Suggest an answer

Log in or Sign up to answer

Hi Jon !

 

Thanks for the answer!, but i´m getting a code error.

tmp.PNG

Jon Bevan _Adaptavist_
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.
Jun 13, 2017

I've updated my answer to fix this.

0 votes
Jon Bevan _Adaptavist_
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.
Jun 13, 2017 • edited

Hi Alejandro,

This script should work for you when configured to run on the Issue Updated event.

// Get the change history for the issue
List<Map> histories = get(issue.self)
        .queryString('expand', 'changelog')
        .asObject(Map)
        .body
        .changelog
        .histories as List<Map>

// Determine whether the reporter was the last updated field
Map reporterChange = histories.isEmpty() ? null : histories
        .last()
        .items
        .find { it['field'] == 'reporter' }

// If the reporter was the last updated field...
if (reporterChange) {
    // Add the previous reporter as a watcher
    def resp = post("/rest/api/2/issue/${issue.key}/watchers")
        .header('Content-Type', 'application/json')
        .body("""\"${reporterChange.from}\"""")
        .asString()
    assert resp.status == 204
}

I hope that helps,
Thanks,
Jon

0 votes
Jon Bevan _Adaptavist_
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.
Jun 06, 2017

Hi Alejandro,

This should be possible using a Script Listener in ScriptRunner for JIRA Cloud, and I was going to provide some example code here for you, but I've run into a problem with the REST API that Atlassian provide for adding a watcher to an issue.

I'll post back here once I've figured out the problem.

Thanks,
Jon

ok Great ! 

It should not be only in the creation of the issue, but also every time that the reporter is modified.

so,  on reporter changed = add old reporter as watcher 

 

Thanks!

Alejandro

 

what i really need is that when the reporter changes, the old one is added to the watcher list.

i couldn´t find any plugin or method to do this.

 

0 votes
AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 08, 2017 • edited

Our feature request mentions some other plugins that could be of use:

Ability to add watchers during issue creation

TAGS
AUG Leaders

Atlassian Community Events