Displaying messages and notifications

Sometimes it might be required to display messages or notifications to the engineer who is currently working with ConSol CM. You can use messages for information concerning the process or the changes which the engineer makes while editing an object. To inform the engineer about events which are not related to the current object, you can create a system notification.

In the following sections, you will learn how to implement messages and notifications for the Web Client.

Messages

The most important method for displaying messages in the Web Client is addValidationError(), in the object workflowApi. It can be used in workflow scripts or in scripts of type Workflow which are called from the workflow but stored in the Admin Tool.

Alternatively to the methods described in this manual, error messages can also be implemented using the Action Framework. Please see the ConSol CM Administrator Manual for further information.

The place where the messages are displayed depends on the parameters passed to the method. There are two options:

Displaying a simple error message

In the following example, a simple message is displayed when the engineer clicks a workflow activity to close a ticket which still has open child tickets. Obviously, the text is not localized and therefore cannot be used in multi-language environments.

// only when all child tickets are closed, the parent ticket (this ticket) can be closed

import com.consol.cmas.common.model.ticket.Ticket

 

Ticket ticket = workflowApi.getTicket()

List<Ticket> ch_tickets = workflowApi.getChildTickets()

 

Boolean all_closed = true

 

ch_tickets.each() { ch_tic ->

Boolean closed = ch_tic.getScopeInfo().isClosedOrDeleted()

log.info 'Child Ticket {$ch_tic.id} is ' + closed

if (closed == false) {

all_closed = false

}

}

 

def text = "Please close all child tickets first. Then you can close the ticket";

 

if (!all_closed) {

workflowApi.addValidationError("INFO",text)

} else {

log.info "Ticket ${ticket.id} was closed."

}

Code example 73: Checking if all child tickets are closed and displaying a message for the engineer, non-localized version

Displaying a localized message using labels

In order to localize the text which is displayed in the Web Client, you can work with labels. Labels are defined in the Admin Tool, navigation group Global Configuration, navigation item Labels. A detailed introduction to labels is provided in the ConSol CM Administrator Manual.

In the following example, an error message is displayed when the engineer clicks a workflow activity to accept the ticket although he is assigned to too many open tickets already. The text which is displayed on the GUI is composed of two components: 

As a comment, the alternative solution with a simple text message is shown.

// Engineer can only accept ticket if he does not have too many tickets already

def curr_eng = workflowApi.currentEngineer

def max_tics = configurationService.getValue("custom-servicedesk","engineer.max.open.tickets")

 

// look for open tickets of current engineer

def engs = []

engs.add(curr_eng.id)

 

TicketCriteria tic_crit = new TicketCriteria()

tic_crit.engineerCriteria = TicketCriteria.EngineerCriteria.assigned(engs as Set)

tic_crit.status = TicketCriteria.Status.OPEN

 

List<Ticket> open_eng_tics = ticketService.getByCriteria(tic_crit)

 

def tic_number = open_eng_tics.size

def loc = engineerService.currentLocale

 

if (tic_number > max_tics) {

log.info 'Too many tickets for engineer ' + engineerService.current + '. Current number is ' + tic_number

// get text from labels defined in AT:

 

def infoText1 = messageProviderService.getMessage("info.wfl.toManyTicketsError1", loc)

def infoText2 = messageProviderService.getMessage("info.wfl.toManyTicketsError2", loc) + max_tics

// alternative solution: workflowApi.addValidationError("INFO","You have too many tickets (" + tic_number + ") already, so you cannot accept another ticket. Maximum allowed number is " + max_tics)

workflowApi.addValidationError("INFO",infoText1 + " " + infoText2)

 

} else {

ticket.setEngineer(curr_eng)

}

workflowApi.reinitializeTrigger("defaultScope/Service_Desk/TimeTriggerDesiredDeadline")

Code example 74: Script of activity "New IT ticket (Accept ticket)", engineer workload is checked

Displaying a localized message without using labels

You can also work with localized values by simply checking the locale as shown in the following example. The major difference between this and the previous example is that the labels can easily be modified using the Admin Tool, thereby being accessible by CM administrators. In contrast, in the solution demonstrated in the current section, the text which is displayed can only be changed by deploying a new version of the workflow. You can decide for yourself which solution might be the best for your requirements.

// only when all child tickets are closed, the parent ticket (this ticket) can be closed

import com.consol.cmas.common.model.ticket.Ticket

 

Ticket ticket = workflowApi.getTicket()

List<Ticket> ch_tickets = workflowApi.getChildTickets()

 

Boolean all_closed = true

 

ch_tickets.each() { ch_tic ->

Boolean closed = ch_tic.getScopeInfo().isClosedOrDeleted()

log.info 'Child Ticket {$ch_tic.id} is ' + closed

if (closed == false) {

all_closed = false

}

}

 

def text

def mylocale = engineerService.getCurrentLocale().toString()

log.info "LOCALE IS NOW $mylocale"

 

if (mylocale.startsWith('en')) {

text = "Please close all child tickets first. Then you can close the ticket";

} else if (mylocale.startsWith('de')) {

text= "Bitte erst alle Child Tickets abschließen. Dann können Sie das Ticket abschließen"

} else { //default

text = "Please close child tickets."

}

if (!all_closed) {

workflowApi.addValidationError("INFO",text)

} else {

println "Ticket ${ticket.id} was closed."

}

Code example 75: Checking if all child tickets are closed and displaying a message for the engineer

Displaying a field-specific message in an ACF

It is also possible to display messages which refer to single fields when filling in ACFs. In this way, you can check if a data field has been filled in correctly and display a message if some value is missing or wrong.

The following example shows the general syntax used for this kind of validation messages. If a ticket field is provided, the message is displayed within the ACF next to this field.

workflowApi.addValidationError(ticket.getField("GROUP_NAME", "FIELD_NAME"), "Value is not valid! Please enter a new one.")

Notifications

Notifications are displayed when clicking the bell icon in the header of the Web Client, next to the link to the engineer profile. If the user allows notifications in the browser, they can also appear in the Windows system tray.

Figure 167: ConSol CM Web Client - Notification with a ticket link

Example: Sending a notification when an email is received

When an email is received for a ticket, you can add an overlay to the ticket icon and send a notification to the assigned engineer. For this purpose, you only need to add an email trigger connected to an automatic activity, where the overlay is added and the notification is sent. The notification can include a link to the ticket.

The script for this activity could look as follows:

def myEngineer = workflowApi.engineer.name

def myTicket = workflowApi.ticket.name

if (myEngineer) {

broadcasterService.notificationBuilder().

withSenderName("System").

withMessage("Email received in your ticket").

withNature("INFO").

withOrigin(myTicket).

withOriginContext("TICKET").

addRecipientName(myEngineer).

build().

send();

}

Code example 76: Workflow script to send a notification