It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Organization automation

Hi guys,

I do not have experience with scripting, and not sure if this can be done by some add-in, so I want to ask if anyone of you has done something similar or can recommend some approach:

  1. when a customer creates an issue in service desk portal, I want to be able (most likely with a post-function during transition) to get the domain out of his email, create Organization if not already existing and add the customer to it. If the Organization exists, just add the customer to it.
    I assume this has to be done via custom code. Any examples how?

  2. During one transition in a Service Desk project, I am creating issue in other project. During this transition I want to copy the Organization from the Service Desk project and save it in other custom field in the other project.
    Do you know any Add-in that can do this? I am using the JIRA Misc Workflow Extensions, but it does not support the Organization field.

This is on Cloud.

Thank you in advance for your response.





5 answers


You could achieve this using ScriptRunner for JIRA Cloud and the REST APIs for JSD.

In your post function on the Create Issue transition, you would need to write a script a bit like this:

def creatorEmailAddress = issue.fields.creator.emailAddress
def creatorDomain = creatorEmailAddress.split('@')[0]
// We need to retrieve a list of the existing organisations to compare
// the email domain
// NB - You might need to paginate this request, see the documentation
def orgReq = get("/rest/servicedeskapi/organization")
assert orgReq.status == 200
def existingOrganisations = orgReq.body.values
// I've assumed here that the name of the organisation will match the
// domain exactly, but you might need different logic here
def organization = existingOrganisations.find { == creatorDomain }
// Create the organization if it doesn't exist
if (organization == null) {
    def createReq = post("/rest/servicedeskapi/organization")
						.header('Content-Type', 'application/json')
							name: creatorDomain
    assert createReq.status == 201
    organization = createReq.body
// Now we add the user
def addReq = put("/rest/servicedeskapi/organization/${}/user")
        .header('Content-Type', 'application/json')
            usernames: [
assert addReq.status == 204

For your other question, you can definitely do that with ScriptRunner too. On the relevant transition you would need a script a little bit like this:

// Get the field ids
def fields = get('/rest/api/2/field')
        .body as List<Map>

def organizationFieldId = fields.find { == "Organization" }.id
def otherCustomFieldId = fields.find { == "Copy of Organization" }.id

// This would need changing to meet your specific requirements
def targetIssueToUpdate = "EXAMPLE-1"
def organization = issue.fields[organizationFieldId]
def updateReq = put("/rest/api/2/issue/${targetIssueToUpdate}")
                    .header('Content-Type', 'application/json')
                        fields: [
                            (otherCustomFieldId): estimates['Development Sub-Task']

// check that updating the issue worked
assert updateReq.status == 204

I hope that helps,


EDIT: fixed bugs in code

If only REST calls to the Server version were this easy.

Thank you for your prompt answer Jon.

I will give it a try..

Thanks again

Hi Jon,

Tried the first script on Create transition, and I found following errors:

CorrelationId: 7b06ad8b-2f6f-424a-9352-6d666191f75a
RUN Script identifier: 3946e851-3ec9-4faa-84eb-3b4f0dc9e847 ('Create' transition made for issue UTP-9) Took 100ms Logs:
2017-02-03 18:57:49,044 ERROR - Cannot get property 'emailAddress' on null object
2017-02-03 18:57:49,055 ERROR - Class:, Config: [, uuid:3946e851-3ec9-4faa-84eb-3b4f0dc9e847, description:Organization from Email, condition:, executionUser:ADD_ON, additionalCode:def creatorEmailAddress = issue.creator.emailAddress

Not quite sure how to bypass this...

Thanks in advance.




Try configuring the post function to run after the issue index event:




Thanks Jon,

Tried the suggestion - moved the post-function after the indexing, but got again the same errors.

There are errors in the code window where the variables are defined.

Sorry again for bothering.


Apologies Kilme, the first line of the code needs to be:

def creatorEmailAddress = issue.fields.creator.emailAddress

Given you are not using this post function on the Create transition you should be able to move it back to the top of the list of post functions.

Also, some of the errors reported in the code editor are misleading, and we're working on removing them.

Thanks, Jon

Thanks again Jon,

I moved a little bit forward now, got the message as on the screenshot.

Tried few combinations in line23 (changed to and line35 (changed to, but got other errors, so I returned it as it was - as on the screenshot



Line 35 needs changing to:

Hi Jon,

I have applied this change, and now if I execute with the Add-on user, I get this error:

2017-02-07 17:56:02,097 WARN - PUT request to{}/user returned an error code: status: 401 - Unauthorized


When I go with the Initiating user, I get this one:

2017-02-07 18:03:59,645 WARN - PUT request to{}/user returned an error code: status: 403 - Forbidden
body: {"error": "Add-on 'com.onresolve.jira.groovy.groovyrunner' blocked from impersonating the user because the access token does not have the required scope(s)"}
2017-02-07 18:03:59,647 INFO - PUT /rest/servicedeskapi/organization/{}/user asString Request Duration: 188ms
2017-02-07 18:03:59,650 ERROR - assert addReq.status == 204
       |      |      |
       |      403    false
       status: 403 - Forbidden


Any suggestions on this one?



Hi Klime,

Looks like you found another bug in my code!

That PUT request line should look like:

def addReq = put("/rest/servicedeskapi/organization/${}/user")

with a $ symbol before the open curly brace.

That should fix the problem I think, as long as you run this as the ScriptRunner Add-on user, but you'll need to make sure that that user already has permission to create organisations in JSD.

Thanks, Jon

Jon, just to say thank you for all of your effort on trying to help me with this.

I got the same errors with the latest suggestion, and the client unfortunately gave up from this feature.

Thank you again.




Hi Klime,
Nice automation and a nice answer from Jon. We want to include an organisation example in our documentation for ScriptRunner for server and your first use case is really interesting.

I have a question though. What if the customer's email is a gmail or hotmail ? This will create a Gmail organization and if another customer with a gmail account creates an issue then you will end up having a Gmail organization and it's members being completely strangers. 

Was a full tutorial created for this by chance?

Hi Thanos,

You can use this case freely in your documentation, however, I did not make it work in my environment.

Jon did a great job trying to help - I am sure it is some minor change, but the client gave up from this.

Thank you all for your engagement.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Desk

The Complete Guide to Atlassian for ITSM

Hi Atlassian Community! This is Teresa from the Atlassian team. My colleague Paul Buffington @Buff and I are excited to share a brand new ITSM resource we’ve created – "The Complete Guide to At...

596 views 7 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you