auto add organization on creation of ticket

Laurens Coppens Community Champion 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

6 answers

1 accepted

This widget could not be displayed.

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

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?

 

 

 

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 ;)

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?

This widget could not be displayed.

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.

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 Champion 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.

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

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?


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

This widget could not be displayed.

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 ?

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

This widget could not be displayed.

Hi, 

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

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

Ibrahim

This widget could not be displayed.

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

83 views 1 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you