auto add organization on creation of ticket

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 22, 2017

When a service desk agent creates a ticket, organization is not automatically added.

Is it possible to add this with the automation plugin or with scriptrunner?

Issue's created through the customer portel does auto add the organization

10 answers

1 accepted

6 votes
Answer accepted
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2017

Hi Laurens,

So a script listener during an Issue Created event would be 

import com.atlassian.fugue.Option
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.organization.OrganizationsQuery
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequest
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequestImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk")

@PluginModule
ServiceDeskManager serviceDeskManager

@PluginModule
OrganizationService organizationService

MutableIssue issue = issue

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(issue.projectObject)

// if the project is not a Service Desk one then do nothing
if (serviceDeskProject.isLeft()) {
    log.error "${serviceDeskProject?.left()?.get()}"
    return
}

def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer

// get the available organizations for that project
def organizationsQuery = new OrganizationsQuery() {
    @Override
    Option<Integer> serviceDeskId() {

        return new Option.Some<Integer>(serviceDeskId)
    }

    @Override
    LimitedPagedRequest pagedRequest() {
        return new LimitedPagedRequestImpl(0, 50, 100)
    }
}

// get all the organizations configured for that project
def organizationsToAdd = organizationService.getOrganizations(currentUser, organizationsQuery)?.right()?.get()?.results

// get the Organizations custom field
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Organizations")

// finally update the organizations custom field
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), organizationsToAdd), new DefaultIssueChangeHolder())

What it actually does is if a project gets created (as you mentioned - not through the customer portal) then it will update the Organizations custom field in order to include all the Organizations configured for that project. Of course this script can be edited in order to match different criteria (if the reporter of an issue is member of any organization, etc..). The key thing in this script is the 'access' to the JIRA Service Desk API and a way to start using it. 

regards, Thanos

Ferhat OZDAG June 1, 2017

Hi

we recently started to use Jira Service Desk, we have used another service desk appliation.

in that app, you can add domain and when case created system knows the customer through the domain and add the organization.

Why do i run a script to catch the customer to add into organization.

it should be conguriable !!

is it a way to make automation rule to catch?

 

 

 

Like # people like this
Yousaf February 20, 2018

Hi Thanos,

 

could you also write a script where the organization is added automatically when an issue is created by a customer over the customer portal?

 

Thanks ;)

Like # people like this
Maksim Smetannikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 8, 2018

Hi!

i am getting a compile issue when calling

def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer

[static type checking] - No such property : id for class : R

same issue for results
def organizationsToAdd = organizationService.getOrganizations(currentUser, organizationsQuery)?.right()?.get()?.results

 what can cause the problem?

Antonio D'Errico November 25, 2019

@Thanos Batagiannis [Adaptavist] 

what i'm doing wrong here?

Screenshot 2019-11-25 at 12.07.39.png

Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2019

Hi @Antonio D_Errico 

Is the old version of Community that was wrongly escaping some symbols in a code area. I edited my answer above. 

So when you see &lt; this is the symbol < and the symbol is wrongly encoded to &gt; 

Antonio D'Errico November 25, 2019

Hi @Thanos Batagiannis [Adaptavist] 

 

when i run this in the console this error occurs:

 

The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script27.groovy: 37: The return type of com.atlassian.fugue.Option serviceDeskId() in Script27$1 is incompatible with java.util.Optional in com.atlassian.servicedesk.api.organization.OrganizationsQuery . At [37:5] @ line 37, column 5. @Override ^ 1 error </pre>.

 

Screenshot at Nov 25 12-27-25.png

Cheers

Toni

Like Jawann Swislow likes this
3 votes
Clyde Moseley December 18, 2017

I am running into the same challenges with my implementation.

  1. If a customer who belongs to an organization creates a ticket via the portal, their organization will be added to the ticket unless they are members of more than on organization, then it will be a private request (Organization is null).
  2. If a Service Desk agent creates the ticket via the portal on behalf of the same customer, the organization will be added to the ticket unless they are members of more than on organization, then it will be a private request (Organization is null).
  3. In either scenario above, there is the option to Share the request with either organization while creating the ticket - but not both.
  4. If an agent is creating a ticket on behalf of a user using JIRA, there is no ability to manage the Organization and the Organization is not set even if the Reporter is changed to the customer.
  5. The Organizations field is be displayed and can be set on the JIRA Edit Screen after initial ticket creation.

There is a workaround to number 4 with the Extension for JIRA Service Desk plugin which has custom fields for Organization, Request Type, and Additional Participants.  The Organization custom field can be added to the Create Request screen in JIRA and you can select the customers Organization while you are creating the ticket.

Patrick S
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 16, 2018

Big upvote for the workaround to number 4.  That's a huge use-case in our environment and just made the lives of everyone on my team much easier (and allowed me to remove some scripting that I wrote poorly)!

Murugan Mittapalli February 4, 2021

Hi Clyde,

Did you get the solution for this first point?

If a customer who belongs to an organization creates a ticket via the portal, their organization will be added to the ticket unless they are members of more than on organization, then it will be a private request (Organization is null)

 

Thank you.

0 votes
Conor_Hattwell-Leach
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 4, 2019

I found my answer to this via Dieter's answer in this thread.

 

Workflow post hooks. You can set the organisation on the create transition post hook.  It will only let you assign one organisation for the whole workflow. For my use that was sufficient. You could create multiple differing workflows and projects per organisation...

 

Related official jira documentation of this workaround

rae edwards May 27, 2020

hi @Thanos Batagiannis [Adaptavist] 

I have the same problem reported by @Yousaf in February 2020 . How can the ticket be automatically shared with the organization when the customer creates a ticket? Currently, the default is set to "Private request" . However, we want the default to be "Share with organization" when the customer is setup in JSD as part of an organization. If the customer is not setup under an organization, then it makes sense to have the default as "Private request". Look forward to your comment. Thanks.

Ian Jones November 6, 2020

Did you find an answer @Thanos Batagiannis [Adaptavist] ?

We are struggling to ideally remove the private request as it is not relevant for us, or failing this automatically add that individual users Organization to the issue as it is created / saved.  Doesn't seem a huge ask but makes such different for people when agents have to manually go in and try to identify the organisation someone belongs to and then edit the ticket to add this. Does anyone have any suggestions on how to achieve the above?

Neil Haines
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 4, 2021

This response may be a bit late, hopefully you have already found the answer by now but just in case please see below.

 

Admins can change the default Organization sharing behaviour by going to Settings > Products > Configuration (under Jira Service Management), within the "Organization management" section.

Should new requests automatically be shared with a customer's organization?

Change setting to yes, this will then automatically share with the organisation when ticket is created.

Like nicolas likes this
0 votes
Salomie September 20, 2019

@Hanna Blomqvist

In response to your question about a solution for the Cloud Version...I have a workaround that works for us...my workflow is set up as follows:

1. I have created a group called "DSG" and all the service desk agents belonging to the DSG Organization belongs to this group. I did not create an organization for DSG, specifically because I need to manually control access of this group.

I unfortunately do not have a working solution for the case where you would prefer to let users automatically become part of an organization based on their domain (instead of manually managing a group). 

2. On the Project where they will act as service desk agents, Under people - I have a added the Group, "DSG".  I have granted the correct level for the Service desk Agent role.

3. The Workflow requires the Add-On JMWE "Jira Miscellaneous workflow extensions"

Refer to the screenshot below on the Add organization step specifically.This is done during the initial Create Issue Step, added as a Post Function.

image.png
image.png

Vladimir Kiesner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 20, 2019

Thanks for help. Unfortunately, this is not what i need.

Problem is, when agent create issue (phone call with customer) we want one single operation: create issue, set description, spent time and organisation and close issue.

One form, one action.

Current Jira capabilities require tocreate issue, and edit it after, to set organisation.

Your solution allows to set only one predefined organisation, but we need to choose from list of all currently existed organisations.

0 votes
Salomie July 11, 2019

I found a way of adding an organization to any issue created by using the Jira Miscellaneous Workflow Extensions Add On - we use a Jira Cloud Instance by the way...On the "Create" Step of the workflow, Update the issue field "Organizations" with JMWE.

I am very conscious of the plugin costs on our site, and always try to make do with what we have...Thankfully this time there was another alternative...  ;)

Vladimir Kiesner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 17, 2019

Please, can you be more specific? I am new in this area and unfortunately can not reproduce your solution.

I installed JMWE, but unable to "Update the issue field "Organizations" with JMWE."

0 votes
Tom November 14, 2018

Laurens,

In your original question you wrote "Issue's created through the customer portel does auto add the organization".

Did you mean to say does NOT or are you getting this to work with another solution or script?

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2018

@Tom

Not sure how i did it then, but now you can just add an automation rule with the automation plugin and add it like that.

I still use this script to add it to all projects but automation is a bit more user friendly :)

Nicholas Fish
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 4, 2019

Hi @Laurens Coppens ,

 

Please could you detail how you were able to achieve this as we have a similar issue and can't find 'organisation' in the automation rule field list.

 

Regards,

 

Nick

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 4, 2019

@Nicholas Fish You need to use the automation plugin by codebarrel, not the default build in automation of service desk.

0 votes
david parker
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 12, 2018

Sorry to ask but has anyone found a way to use the scriptrunner code to only grab the reporters organisations. btw i am a relative novice to scripting in JIRA.

The use case is when you create an issue on behalf of a customer like on the phone so the reporter is an external customer and generally an email address. that email address is the "account" and is a part of an organization to logically group our customers.

So  when i create the issue i only want the organisation the reporter is a member of added not all the organizations like the code achieves .

Ive tried modify the currentUser to be issue.getReporter() and issue.getReporterUser() but cant get it to work.

Any suggestions or ideas?

thanks

0 votes
Ibrahim TOUMI
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 8, 2018

Hi, 

Yes. This a static check but no a real errors.

So you can run your script and it will work fine.

Ibrahim

Maksim Smetannikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 8, 2018

Thank

0 votes
Ibrahim TOUMI
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 11, 2018

Hi all,

 

i am getting a compile issue when calling

def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer

[static type checking] - No such property : id for class : R

same issue for results
def organizationsToAdd = organizationService.getOrganizations(currentUser, organizationsQuery)?.right()?.get()?.results

 

could you please help ?

Maksim Smetannikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 8, 2018

I have the same problem. @Ibrahim TOUMI you found a solution?

Laurens Coppens
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 22, 2017

Hi Mari,

Thanks for you respons, but i don't see how that url gives a solution to my problem.

If a servicedesk Agent creates a ticket (not through the customer portal) an organization is not automatically added.

I want to do this automatically, now my agents need to manually fill in an organization after creating a ticket.

Hanna Blomqvist February 16, 2017

Is there a way to automatically add the organization in the cloud version ?

Like # people like this
Alphonso Burger
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 2, 2017

I'm currently running a trial of the cloud version and it seems this is still the case or am I just doing something wrong?


Stefano Falasca
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 20, 2017

I've same problem. My agents can insert issue, by calling phone, so should be able to type customer name or organizzation. Is possible make this ? I tried to add organizzation to screen create issue, but it is not showed.

Robbert Struijkenkamp
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 28, 2017

Same here. 

 

1) we can't show the field "Organisation" in the create screen

2) 98% of the time I want the organisation to be the reporter's organisation. 

 

If this could be done in "automation" i would be pleased

Suggest an answer

Log in or Sign up to answer