since v12.25
A CreateTicketOperationBuilder can be used to build a create-operation for a new ticket.
To obtain an instance of the CreateTicketOperationBuilder call the create()
Method of the TicketOperationBuilder.
An example of a method which creates a new ticket for the provided agent and the provided category and account would look like this:
@Inject
private TicketOperationBuilder ticketOperationBuilder;
public Long createNewTicket(User user, Category category, Account account) {
try {
ticketOperationBuilder.create()
.with(user, category, account)
.primaryToAddress(new InternetAddress("meier@novomind.com"))
.additionalToAddresses(Arrays.asList(new InternetAddress("info@novomind.com")))
.ccAddresses(Arrays.asList(new InternetAddress("support@novomind.com")))
.bccAddresses(Arrays.asList(new InternetAddress("schulz@novomind.com")))
.attachments(Arrays.asList("Bild1.jpg","Bild2.jpg"))
.header("X-Test1", "4711")
.header("X-Test2", "4712")
.processId(12345L)
.editTime(Duration.ofMinutes(2))
.html("<p><b>Test</b></p>\n")
.subject("Test")
.language(Locale.GERMAN)
// .createAndSend() // also available
// .createAndClose() // also available
.createAndEnqueue()
.build()
.execute()
.getTicketId();
} catch (ValidationException e) {
// ValidationException if one of the provided attributes are not valid (e.g. null values)
} catch (OperationFailedException e) {
// OperationFailedException if the operation failed
}
return null;
}