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()
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kannpitcha ,
My apologies for this.
Please try reaccessing the link.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.