Scriptrunner - cannot update reporter

Kannpitcha Paponphatsiri October 30, 2023

The ticket details are from external system and as I know, reporter need to be set by account ID, therefore, I define the name of reporter as a custom field and use scriptrunner to find the account ID of that name and place it as reporter, during the create transition. However, the scriptrunner showed that it successfully updated the reporter by account ID, I cannot see the change, even I use postman to check to reporter of that request. Here's my code:

import java.net.URLEncoder

def IssueKey = issue.key

def data = get("/rest/api/3/issue/${IssueKey}").header("Content-Type", "application/json").asObject(Map).body
def Fields = data.fields
def name = Fields.customfield_10072

// Encode the 'name' variable
def encodedName = URLEncoder.encode(name, "UTF-8")

def url = "/rest/api/3/groupuserpicker?query=${encodedName}"
def response = get(url).header("Content-Type", "application/json").asObject(Map).body
def users = response.users
def user = users.users
def accid = user.accountId
def resultAccId = accid[0].toString()

put("/rest/api/3/issue/${IssueKey}")
         .header("Content-Type", "application/json")
         .body([
         fields:[
                   reporter: {
                                 id : resultAccId
                   }
         ]
])
          .asString()

2 answers

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2023

Hi Kannpitcha ,

 

I can confirm that I have added an example here, which can be run on the Script Console and shows how to search for a user and set them as the reporter when creating an issue.

This example can help create the script you require to achieve your requirements.

I hope this helps.

Regards,

Kristian

Kannpitcha Paponphatsiri November 1, 2023

I cannot access the link (Access denied)

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 2, 2023

Hi Kannpitcha ,

My apologies for this.

Please try reaccessing the link.

Regards,

Kristian

Kannpitcha Paponphatsiri November 2, 2023

Thank you for your help!

0 votes
Andrzej Wieczorek October 30, 2023

Hi,

I think in your code, there is an issue in line where you access user accountId. 

Reference users.users returns a collection, so you should amend your code to be

 

def user = users.users[0]
def accid = user.accountId
def resultAccId = accid.toString()

 

Suggest an answer

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

Atlassian Community Events