Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Setting organisation into issue with API call inside script runner

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

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
Site Admin
TAGS
AUG Leaders

Atlassian Community Events