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

Issue with ScriptRunner post function "Add group of watchers to a ticket"

Jordan Artman March 15, 2021

Hoping someone can help with the below request:

I am trying to add a group of people as watchers at time of ticket creation. I have tried both of these codes and they are failing.

Based on issue type:

if (issue.fields.issuetype.id == "11200") { 

    def issueKey = issue.key

    def members = get('/rest/api/2/group?groupname=chewy-brands&expand=users').asObject(Map).body.users.items

  //ADD ENTIRE GROUP TO ISSUE AS WATCHERS

        for (def i = 0; i < members.size(); i++) {

            post("/rest/api/2/issue/" + issueKey + "/watchers")

            .header('Content-Type', 'application/json')

            .body("\"" + members[i].name +"\"")

            .asString()

        }

}

Based on request type:

def issueKey = issue.key

if (request) {

if (request.requestType.id == '176') {
// GET ALL MEMBERS OF THE pharmacy group
def members = get('/rest/api/2/group?groupname=pharmacypromo&expand=users').asObject(Map).body.users.items

// ADD ENTIRE GROUP TO ISSUE AS WATCHERS
for (def i = 0; i < members.size(); i++) {
post("/rest/api/2/issue/" + issueKey + "/watchers")
.header('Content-Type', 'application/json')
.body("\"" + members[i].name +"\"")
.asString()
}
}
}

*ERROR MESSAGE: [request] and [issue] are both undeclared

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events