Important Classes and Objects

This chapter discusses the following:

Introduction

To make ConSol CM script programming easier, the CM Workflow API provides easy access to objects which are frequently used. Furthermore, convenience classes and methods provide a short way to various objects and methods.

Important Objects

Some objects are implicitly present in workflow scripts.

The same objects are not implicitly present in Admin Tool scripts, i.e. within Admin Tool scripts you will have to use import statements for the respective classes or packages!

Ticket

In every workflow script, the current ticket can be easily accessed by the object ticket. It is derived from the class Ticket and is implicitly present. No import and no instantiation is required.

Example:

def myId = ticket.getId()

//or shorter, Groovy-like:

def myId = ticket.id

Code example 13: Using the ticket object

workflowAPI

The object workflowApi is also implicitly present. It provides easy access to the interface WorkflowContextService which is used for numerous operations.

Examples:

workflowApi.sendEmail(contact_e,subj,text,replyto,null)

Code example 14: Using workflowApi to send an e-mail (older variant; current variant would mean using an object of class Mail)

def curr_eng = workflowApi.getCurrentEngineer()

ticket.setEngineer(curr_eng)

Code example 15: Using workflowApi to assign a ticket to current engineer

workflowApi.deactivateTimer("defaultScope/Service_Desk/TimeTrigger1")

Code example 16: Using workflowApi to deactivate a trigger

workflowApi.addValidationError("1", "The ticket cannot be closed before a solution is provided. Please fill-in solution and mark it with text class SOLUTION first.")

Code example 17: Using workflowApi to display a GUI message for the engineer/user

trigger

This object is implicitly available in the scripts of time triggers (script on timer start, script after timer).

def addedEscalMillis = 0

switch (ticket.queue.name) {

case "HelpDesk_1st_Level":

addedEscalMillis = 12*60*60*1000L;

break;

case "HelpDesk_2nd_Level":

addedEscalMillis = 24*60*60*1000L;

break;

case "ServiceDesk":

addedEscalMillis = 4*60*60*1000L;

}

trigger.setDueTime(addedEscalMillis)

Code example 18: Example for a script on timer start

Convenience Classes and Methods

The ConSol CM API provides various convenience interfaces and methods which make access to most objects of every-day CM programming a lot easier. Most of those convenience interfaces are part of the package com.consol.cmas.common.service and its sub-packages. Please refer to the ConSol CM Java API documentation for details. Here, we will show you some examples which might prove useful for most CM programmers.

The implementing instance of the interface is always available by replacing the first letter, which is a capital letter, in the class name by a lower case one, e.g. the object (singleton) with the interface EngineerService is available with the object engineerService, see Example 2.

Example 1: Using the ConfigurationService to Retrieve System Properties

def tic_nr = configurationService.getValue("custom-mycompany-properties","engineer_management.ticket.nr")

 

// then: ... do something with the engineer management ticket,

// e.g. find out the name of the next engineer a service ticket

//should be assigned

Code example 19: Using the ConfigurationService to retrieve the number of the engineer management ticket

def baseUrl = configurationService.getValue("custom-mycompany-properties","base.url.mycompany")

def url = baseUrl + "/cm-client/ticket/ticket_name/" + ticket.getName()

def itComplete = url + " " + ticket.getName()

//alternative: def itComplete = "${url} ${ticket.name}"

 

// ... do something with the ticket url, e.g. place a link to a child ticket in a table of the parent ticket

Code example 20: Using the ConfigurationService to retrieve base URL of the system

Example 2: Using the EngineerService to Assign the Ticket to an Approver

// Script does the following:

// Hand-over ticket to approver only when approver has been set in ticket as additional engineer

// Import package, because classes are not available in workflow otherwise:

import com.consol.cmas.common.model.ticket.user.function.*

 

// Get the name of the approver which has been written/stored in a Custom Field, // namely the field with the name

// CF_ApproverName in the Custom Field Group CF_GroupApproverData. The value could be for example Mr. Miller:

def gen = ticket.get("CF_GroupApproverData.CF_ApproverName").getName()

 

// Get the engineer object where the name Mr. Miller is set, i.e.

// the engineer object of the desired approver:

def gen_eng = engineerService.getByName(gen)

 

// Get the ticketFunction object which represents the ticketFunction (engineer role) Approver:

TicketFunction tf = ticketFunctionService.getByName("Approver")

 

// Add the engineer object of Mr. Miller as Approver. i.e.

// in the ticketFunction (engineer role) Approver to the ticket.

// One of the paramaters is ticket. This does not have to be instantiated,

// because it is implicitly present in workflow

// scripts:

def tu = ticketUserService.addTicketUser(ticket, gen_eng, tf, "Approver")

 

// Assign the ticket to the engineer, i.e. set the engineer Mr. Miller also as ticket owner.

def tic2 = workflowApi.assignEngineer(ticket, gen_eng)

Code example 21: Use of EngineerService

We have two assignments here:

  1. Mr. Miller is set as additional engineer in the engineer role Approver.
  2. Mr. Miller is set as ticket owner.

Example 3: Using EnumService to Retrieve an Enum Value by Name

def enumValueMLA = enumService.getValueByName( "priority", "REGULAR" )

ticket.set( "helpdesk_fields.prio", enumValueMLA )

Code example 22: Using EnumService to retrieve an enum value by name

Example 4: Using the TicketService to Retrieve All Tickets of a Certain View

List<Ticket> mylist = ticketService.getByView(new ViewCriteria(

viewService.getByName("helpdesk_active_tickets"),

ViewAssignmentParameter.allAssignedTickets(),

ViewGroupParameter.allTickets(),

viewOrderParameter.addByName(true)))

Code example 23: Using TicketService to find ticket of a view

Example 5: Using the EngineerRoleRelationService to Send an E-Mail to All Engineers of a Role

// Send e-mail to all engineers of a regular role

 

def mail = new Mail()

mail.setTo(engineerRoleRelationService.getEngineersWithRoles(roleService.getByName("Supervisor"))*.email.join(","))

mail.setSubject("Ticket (${ticket.name}) -- Escalation!")

mail.setText(workflowApi.renderTemplate("Ticket escalation note to supervisor"))

mail.send()

Code example 24: Using the EngineerRoleRelationService to send an e-mail to all engineers of a role