Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create a ServiceDesk customer using Scriptrunner

Narelle Edwards June 27, 2022

Hi

Would really appreciate some help. I need to create a Service Desk Customer (as opposed to a 'user') via a Groovy script, but simply can't figure out how to use the builder correctly or find an example to work from.  I'm on JSM v4.20.9 Data Centre.

I've tried every permutation I can think of. The very cut down version below yields "The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script2.groovy: 12: unable to resolve class newCreateBuilder"

Any help gratefully received!

 

import com.atlassian.servicedesk.api.user.CheckedUser
import com.atlassian.servicedesk.api.customer.CustomerService
import com.atlassian.servicedesk.api.customer.CustomerCreateParameters
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
 
CustomerCreateParameters.Builder customerPara = new newCreateBuilder();
   
def customer = customerPara('demo.email@yahoo.com','A Name').build()
   
def created = customerService.createCustomer(loggedInUser, customer)

2 answers

2 accepted

2 votes
Answer accepted
Chu Dam
Community Champion
June 27, 2022

Hi @Narelle Edwards 

My approach here would be a bit different: I would prefer to use the API to create a customer account cause the API makes it really easy to do that... 

For version 4.20.x, there is an experimental API to create a customer:
https://docs.atlassian.com/jira-servicedesk/REST/4.20.0/#servicedeskapi/customer-createCustomer

Then you can code the API call with Scriptrunner like that: 

I hope this helps. 

Cheers,
Dam. 

Narelle Edwards June 28, 2022

Hi

I wondered if that might be a good option with a couple of the Adaptavist Library 'recipes' heading in that direction, it just 'feels' odd making an API call when it appears the Class should be able to do it.

I hadn't found an example of using the API in that manner with a Post function so those links are awesome - thank you!

Like # people like this
Chu Dam
Community Champion
June 28, 2022

Even for internal API calls let's say... and as many organisations consider the future in Cloud like @Phill Fox mentioned... using an API is much better in many cases ;) 

I'm glad I helped here :) 

Cheers,
Dam.

0 votes
Answer accepted
Phill Fox
Community Champion
June 28, 2022

As many organisations consider the future in Cloud it makes sense to use the approach (APIs) that are largely consistent between the two hosting options. By doing so it simplifies any future migration as you do not then need to swap the use of classes to APIs just check the API definitions to make sure they are compatible. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events