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

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events