Action scripts

Actions scripts are used to add logic to actions which can be executed for contacts, resources and search results. Optionally, actions can have condition scripts which determine the availability of the action. If a condition script is defined for the action, the action is only available if the condition script returns true. For manual actions, this means that the action is not displayed in the Web Client. For automatic actions, this means that the action script is not executed.

Background knowledge about actions

Actions are available for three types of objects:

Actions for cases are called workflow activities. They are implemented in Scripts of the type Workflow.

Actions can be of the following types:

Manual actions can have forms which are opened when the user clicks the action in the Web Client. They need to be filled out to complete the action, see Action forms.

Available action script types

The script type which is used for action scripts depends on the usage of the script. The following script types are available:

Logic of action scripts

The logic of an action script usually covers two aspects:

If the script is used as a condition script, it has the following purpose:

For update actions, you need to make sure that the action script code does not cause an infinite loop. This could happen, for example if you call the method unitService.update(Unit) in a contact update script.

Working with the current object

The object for which the action is executed is implicitly available in the script. This allows updating the object or performing any other relevant action. The following objects are available:

Defining the behavior after the action

In all action scripts, the behavior of the system after completing the action can be defined by using methods of the class OperationResponseBuilder. An object of this class, named client, is implicitly available in all action scripts, in automatic as well as in manual scripts. This object is also available in workflow scripts.

The client object includes methods for the following operations: 

Please refer to the ConSol CM API documentation for details about the available methods.

Defining the binding of action forms

Auto-binding allows to use action forms to directly manipulate the values of the original object, i.e. the case, contact or resource for which the form is opened. Upon saving the form, the original object is modified automatically. Use client.goToUnit(contact) or client.goToResource(resource) to reload the Web Client page to display the values changed in the form.

By default, auto-binding is enabled if the action does not have an action script. Otherwise, you need to enable it in the script by adding the following code:

def isAutoBindingEnabled() {

return true;

}

You can disable auto-binding by returning “false”. If auto-binding is disabled, changes made in the form are not saved to the object.

Coding examples

Opening the page to create a case

Use one of the following methods:

The following example opens the page to create a case. The queue “Helpdesk” is preselected and some fields are prefilled.

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

 

Ticket ticket = new Ticket();

ticket.setQueue(queueService.getByName("Helpdesk"))

ticket.setSubject("sample subject")

ticket.set("queue_fields.string", "test")

client.goToCreateTicket(ticket)

//to additionally set the main contact use withCustomer()

//client.goToCreateTicket(ticket).withCustomer(unit)

Code example 1: Open the page to create a case

Opening a case and displaying an activity form

Use the following method:

The following example opens the case with the name “100270” and directly opens the activity form of the Dismiss ticket activity.

client.goToTicket("100270").openActivityForm("defaultScope/Service_Desk/Ticket_dismissed/Dismiss_ticket_")

Code example 2: Open a ticket page with an ACF

Displaying messages in the Web Client

You can display messages with either a green or a red background.

The following methods display a message with a green background. The message text can be provided as a string or label:

The following methods display a message with a red background. The message text can be provided as a string or label:

By default, the methods to show messages do not refresh the page. Therefore, any updates to the object performed within the action scripts are not yet visible when the message is displayed. You can append withRefreshContent() to the method to refresh the page before showing the message:

client.showMessage("controlForm.info.executionOK").withRefreshContent()

The following figure shows a message with a green background: