The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Setting organisation into issue with API call inside script runner

Hauke Gulich
September 27, 2023

Hello everyone,

I am migration our server instance to the cloud and I am having issues with setting up the service management project correctly.

The goal is, that the script runner script should set the organsiation based on the email domain. 

I know that this already works with automation, but from my point of view it is not fully thought out and not usable for us as we have customers working with different domains.

So I created a script with this function

 

public void setOrganisationToIssue(String issueKey, String organisationID) {

    def builder = new JsonBuilder()

    def root = builder {

        fields {

            customfield_10002([id: organisationID])

        }

    }

        

    def jsonString = builder.toPrettyString()

    def correctedJson = [fields: [customfield_10002: [[id: 156]]]]

    def correctedJsonString = new JsonBuilder(correctedJson).toPrettyString()

    logger.info(correctedJsonString)

def resp = put("/rest/api/2/issue/SD-104801")

        .header('Content-Type', 'application/json')

        .body(correctedJsonString)

        .asString()

}

 

With this example the result of the json looks like this

 

{
    "fields": {
        "customfield_10002": [
            {
                "id": 156
            }
        ]
    }
}

But I get this error message

body: {"errorMessages":[],"errors":{"customfield_10002":"Die Organisations-ID muss eine Zahl sein."}}

That means, that the organisation ID must be a number.

 

I tried a bunch of different things without any luck. Also I wasn't able to use the json builder, because he removed the arrays and I got a message, that setting the organisation needs to use an array.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Hauke Gulich
September 27, 2023

Its seems like, that the json needs to look like this

{
    "fields": {
        "customfield_10002": [156]
    }
}
At least with postman it works
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events