Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating organization with Script Runner

Berk Öztürk
November 15, 2021

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}"

}
Since organizations field accept array, I stored my filtered data in my organizationValue array. It returned;
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"
    }
  }
]

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Lillian Shibata-Salley
Contributor
December 11, 2018

It's ok - I'll just create each new field for the 10 items... the view in Edit for Checklist is one paragraph of text and doesn't work as a checklist... it's not a list... that's unfortunate and kind of useless if the view isn't ... readable - hope there's a feature request for that and gets fixed one day.

Thanks,

Lillian

TAGS
AUG Leaders

Atlassian Community Events