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

Scriptrunner - cannot update reporter

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.
Oct 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

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.
Nov 02, 2023

Hi Kannpitcha ,

My apologies for this.

Please try reaccessing the link.

Regards,

Kristian

Thank you for your help!

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
Site Admin
TAGS
AUG Leaders

Atlassian Community Events