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

auto add organization on creation of ticket

Laurens Coppens Community Leader Jan 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

7 answers

1 accepted

3 votes
Answer accepted
Thanos Batagiannis [Adaptavist] Community Leader Jan 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 Jun 01, 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 Paul French likes this
Yousaf Feb 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 Owoeye Johnson likes this
Maksim Smetannikov May 08, 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?

2 votes
Clyde Moseley Dec 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 Savago Mar 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)!

Laurens Coppens Community Leader Jan 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 Feb 16, 2017

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

Alphonso Burger Jun 02, 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 Jun 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.

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

0 votes
Ibrahim Toumi Mar 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 May 08, 2018

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

0 votes
Ibrahim Toumi May 08, 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 May 08, 2018

Thank

0 votes
david parker Jun 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
Tom Lamson Nov 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 Nov 15, 2018

@Tom Lamson

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 Jun 04, 2019 • edited

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 Jun 04, 2019

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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

8,313 views 9 18
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