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

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

Ability to add watchers during issue creation

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.

 

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

 

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

Hi Jon !

 

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

tmp.PNG

I've updated my answer to fix this.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

102 views 0 2
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you