You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello everyone! I'm trying to update my organizations custom field which is customfield_10002. I have tried two different bodies, but I have received error from both.
1.
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
JsonSlurper slurper = new JsonSlurper()
def issueKey = 'RFD-2'
def organizationValue = []
def result2 = get('https://berkozturk.atlassian.net/rest/servicedeskapi/organization')
.header('Content-Type', 'application/json')
.asObject(Map)
if (result2.status == 200){
def values = result2.body.get("values")
def filteredItem = values.find { it -> it.name == 'ORG2' }
organizationValue.push(filteredItem);
} else {
return "Failed to find issue: Status: ${result2.status} ${result2.body}"
}
// Note: - Atlassian provide examples for the syntax to set other custom field types in the documentation page at https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#creating-an-issue-examples
def resultSetOrg = put("/rest/api/2/issue/${issueKey}")
// Uncomment the line below if you want to set a field which is not pressent on the screen. Note - If using this you must run the script as the ScriptRunner Add-On User.
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_10002: organizationValue
]
])
.asString()
if (resultSetOrg.status == 204) {
return "The select list field was successfully updated on the ${issueKey} issue"
} else {
return "${resultSetOrg.status}: ${resultSetOrg.body} ${organizationValue}"
}
400: {\"errorMessages\":[],\"errors\":{\"customfield_10002\":\"The Organization ID must be a number\"}} [[id:2, name:ORG2, _links:[self:https://berkozturk.atlassian.net/rest/servicedeskapi/organization/2]]]
2.
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
JsonSlurper slurper = new JsonSlurper()
def issueKey = 'RFD-2'
def organizationValue = []
def result2 = get('https://berkozturk.atlassian.net/rest/servicedeskapi/organization')
.header('Content-Type', 'application/json')
.asObject(Map)
if (result2.status == 200){
def values = result2.body.get("values")
def filteredItem = values.find { it -> it.name == 'ORG2' }
organizationValue.push(filteredItem);
} else {
return "Failed to find issue: Status: ${result2.status} ${result2.body}"
}
/
def resultSetOrg = put("/rest/api/2/issue/${issueKey}")
// Uncomment the line below if you want to set a field which is not pressent on the screen. Note - If using this you must run the script as the ScriptRunner Add-On User.
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_10002: [2]
]
])
.asString()
if (resultSetOrg.status == 204) {
return "The select list field was successfully updated on the ${issueKey} issue"
} else {
return "${resultSetOrg.status}: ${resultSetOrg.body} ${organizationValue}"
}
It returned;
500: {\"errorMessages\":[\"Internal server error\"],\"errors\":{}} [[id:2, name:ORG2, _links:[self:https://berkozturk.atlassian.net/rest/servicedeskapi/organization/2]]]
P.S:
1) organizationValue output
[ { "id": "2", "name": "ORG2", "_links": { "self": "https://berkozturk.atlassian.net/rest/servicedeskapi/organization/2" } } ]
Hi Berk
I believe the organization custom field requires an array of numbers (organization id got from
/rest/servicedeskapi/organization
I ran the code you have and changed one line that added the organization to the field:
organizationValue.push(filteredItem);
to
organizationValue.push(filteredItem.id as int);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Berk Öztürk ,
Welcome to the community.
I think you should try to set the I'd of the organisation and not the whole Organisation Object.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My first case includes the whole object but second one has only id attribute. I got 500 internal server error, when I try to set with Id.
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.