Scripts for the Action Framework

Introduction to Actions

The ConSol CM Action Framework provides the ability to perform actions which are not related to workflow activities, i.e., they can be executed in another context.

There are three types of actions, which are explained in the respective manual sections in detail.

This section includes details about programming action scripts.

Action Types

An action can be of one of the following types:

Script Types

The actions are based on Admin Tool scripts whose types correspond to the purpose of the scripts.

For each action, a condition script can be defined. It has to be associated with the action in the action definition in the Admin Tool. This condition script will be executed before the action script.

Thus, the action script will only be executed in the following situation:

  • No condition script is defined.
  • The condition script returns true.

The following script types are available for the Action Framework:

Programming with the Action Framework

Available and Deprecated Objects

In all available script types (see section Script Types), the behavior of the system after the script can be defined by using the 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 operations like the following: 

Besides those actions, the client object also includes methods to display messages in the Web Client, for example: 

Furthermore, the client object offers a rollback() method.

Please note:

  • The classes and respective objects of ActionScriptResult, ActionScriptResultFactory, PostActionScriptResult, PostActionType and postActivityExecutionHandler are deprecated. Use the new OperationResponseBuilder implementation described above.
  • The method workflowApi.addValidationError(), which can be used to display messages in the Web Client, is still valid.

Overview of the Methods

The following methods are available in the client object (class OperationResponseBuilder). For more details, please refer to the ConSol CM API documentation. A mapping to the old/deprecated objects and methods is provided - this might make it easier for you to exchange the code in your scripts.

New class/method

Deprecated class/method

Note

client.failure()

PostActionType.FAILURE

Sets the OperationType = FAILURE.

client.goToCreateResource(resource)

actionScriptResultFactory.getPostAction(PostActionType.CREATE_RESOURCE, resource)

Opens the create resource page prefilled with data from resource object.

client.goToCreateTicket(ticket)

actionScriptResultFactory.getPostAction(PostActionType.CREATE_TICKET, ticket)

Opens the create ticket page prefilled with data from ticket object.

client.goToCreateTicket(ticket).withCustomer(unit)

actionScriptResultFactory.getPostAction(PostActionType.CREATE_TICKET, ticket, unit)

Opens the create ticket page prefilled with data from ticket and unit object.

client.goToCreateUnit(unit)

actionScriptResultFactory.getPostAction(PostActionType.CREATE_UNIT, unit)

Opens the create customer page prefilled with data from unit object.

client.goToPage("url")

actionScriptResultFactory.getPostAction(PostActionType.GOTO_PAGE, "url");

Opens the given URL.

client.goToResource(resource)

actionScriptResultFactory.getPostAction(PostActionType.GOTO_RESOURCE, resource);

Opens the resource page of the given resource object.

client.goToTicket(ticket)

actionScriptResultFactory.getPostAction(PostActionType.GOTO_TICKET, ticket)

Opens the ticket page of the given ticket object.

client.goToUnit(unit)

actionScriptResultFactory.getPostAction(PostActionType.GOTO_UNIT, unit)

Opens the customer page of the given unit object.

client.goToResource(resource).openActionForm("actionformname")

-

Opens the given action form of the resource.

client.goToUnit(unit).openActionForm("actionformname")

-

Opens the given action form of the customer.

client.goToTicket(ticket)
.openActivityForm("acfpath")

actionScriptResultFactory.getPostAction(PostActionType.GOTO_TICKET, ticket, acfExecutionContext)

Opens the ACF of the current ticket.

client.rollback()

-

Rolls back the action. Optionally, an error message can be provided.

client.showDebugMessage("messageOrLabel")

actionScriptResultFactory.getPostAction(PostActionType.FAILURE, "messageOrLabel")

Shows a red message, the message text can be entered as a string or using a label.

client.showErrorMessage("messageOrLabel")

actionScriptResultFactory.getPostAction(PostActionType.FAILURE, "messageOrLabel")

Shows a red message, the message text can be entered as a string or using a label.

client.showInfoMessage("messageOrLabel")

actionScriptResultFactory.getPostAction(PostActionType.SUCCESS, "messageOrLabel")

Shows a green message, the message text can be entered as a string or using a label.

client.showMessage("messageOrLabel")

actionScriptResultFactory.getPostAction(PostActionType.SUCCESS, "messageOrLabel")

Shows a green message, the message text can be entered as a string or using a label.

client.showWarningMessage("messageOrLabel")

actionScriptResultFactory.getPostAction(PostActionType.SUCCESS, "messageOrLabel")

Shows a green message, the message text can be entered as a string or using a label.

client.success()

PostActionType.SUCCESS

Sets the OperationType = SUCCESS.

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.

Examples

Open the Page to Create a Ticket

Use one of the following methods:

The following example opens the page to create a ticket. 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 62: Open the page to create a ticket

Open a Ticket Page in View Mode

Use the following method:

The following example opens the ticket “newtic”. Instead of passing a ticket object to the method, you can also provide the ticket name or ID.

client.goToTicket(newtic)

Code example 63: Open the ticket page in view mode

Open a Ticket Page with ACF

Use the following method:

The following example opens the ticket 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 64: Open a ticket page with an ACF

Open the Page to Create a Customer

Use the following method:

The following example opens the page to create a new contact for the company. Some data fields are already prefilled.

// used for companies in end customers group to create new contacts easily

def myunit = new Unit()

 

def mycustomergroup = customerGroupService.getByName("MyCustomerGroup")

myunit.setCustomerGroup(mycustomergroup)

 

def mycustomerdefinition = unitDefinitionService.getByName("customer")

myunit.setDefinition(mycustomerdefinition)

 

myunit.set("company()", unit)

myunit.set("customer.firstname", "CM")

myunit.set("customer.name", "Consultant")

 

client.goToCreateUnit(myunit)

Code example 65: Company action script (“unit” is the current company) to open the page for creating a new contact

Open a URL

Use the following method:

The following example opens the URL which is saved in a company field.

// opens company's web site

def url = unit.get("companyData.url")

 

if (!url) {

client.showErrorMessage("error.script.no.url")

} else {

client.goToPage(url)

}

Code example 66: Open a URL

Display Result Message in the Web Client: SUCCESS, Green Messages

There are several methods to define messages with a green background:

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()

Display Result Message in Web Client: FAILURE, ERROR, Red Messages

There are several methods to define messages with a red background:

Working with Relation Actions

Relation actions are available for all three main object types and are defined in the Admin Tool. Please see the detailed explanations in the respective sections of this manual.

A relation action is executed when the relation is

It is not executed if the comment of the relation has been changed.

Please note that a relation action is always executed when the object type for which the relation is defined is involved. As a consequence, two actions will be executed in case the source as well as the target object belong to a type with a relation action!

In scripts which define the relation actions, the following objects are available: 

It is possible to distinguish between operations where a relation has been added and operations where a relation has been removed. Use the context parameter actionType for this purpose. It can be used in the condition script, e.g., to control if the action script should be executed or not, or in the action script itself. The actionType can be either of two values: 

Example for a Relation Action

In the following example, the person who is the contact person for an SLA should receive an email whenever a new relation for this SLA to a customer has been established or has been deleted.

Perform the following steps to create the relation action:

  1. Define a relation, in this example the SLA_to_Company_Relation, with source = resource type SLAs and target = company, several customer groups.
  2. Write the resource action script, in this example: SLA_CompanyRelationAction.groovy.
  3. Define a resource action (in this example: SLA_CompanyRelationAction) of type “Relation” which uses the script as action script.
  4. Assign the resource action to a resource type, in the example to the type SLAs.
  5. Test the desired use case in the Web Client.

Example relation action script SLA_CompanyRelationAction.groovy:

import com.consol.cmas.common.model.mail.MailSendHolder

 

def myUnit = relation.targetUnit

def myUnitDef = relation.targetUnit.definition.name

def nameField

def groupField

 

switch(myUnitDef) {

case "ResellerCompany": nameField = "company_name";

break;

case "company": nameField = "name1";

break;

case "DirCustCompany": nameField = "dir_cust_company_name"

break;

}

 

def myCustName = myUnit.get(nameField)

def contPersMail = resource.get("SLA_Fields_basic.responsible_person_email")

if (contPersMail) {

// Send an email asynchronuously. Mail object is not available outside workflow context!

def pResName = resource.get("SLA_Fields_basic.SLA_Name")

 

// alternative to fixed text: use text template, not shown here

 

// distinguish between ADD and REMOVE of relation

def relOp

if (actionType == "ADD"){

relOp = "added to "

} else if(actionType == "REMOVE") {

relOp = "removed from "

}

def pText = "A relation has been " + relOp + "from resource " + pResName + " to company " + myCustName

def pTo = contPersMail

def pSubject = " new or deleted SLA relation - please take care"

def pHtml = false

def pFromEmail = configurationService.getValue("cmweb-server-adapter","mail.reply.to")

 

def holder = MailSendHolder.createSelfSendHolder(pText, pHtml, null, null)

holder.setSubject(pSubject)

holder.setTo(pTo)

holder.setFrom(pFromEmail)

mailService.sendMailAsynchronous(holder)

} else {

log.info 'No mail sent to SLA contact person, no email address found'

}

Code example 67: Relation action script to send an email when a resource-company relation has been created or deleted

Working With the Data of Control Forms

Control Form-Specific Objects

Two specific objects are available in scripts which deal with Control Forms (see section Control Forms):

The two objects are: 

The class ControlFormService includes several methods to retrieve Control Forms.

Auto-binding

The auto-binding setting defines whether changes to the values in the form also affect the original object.

Auto-binding disabled

Add the following line to the script to disable auto-binding:

def isAutoBindingEnabled() {

return false;

}

The values of the form are available only within the form. They can be retrieved using the formFields object. The original object, i.e., the ticket, customer or resource for which the form is opened, is not modified upon saving the form.

Auto-binding enabled

Add the following line to the script to enable auto-binding:

def isAutoBindingEnabled() {

return true;

}

The values of the form are used to manipulate the values of the original object, because there is a binding between the data field in the form and the data field in the object. The form values are also available in the formFields object, but the original object, i.e., the ticket, customer or resource for which the form is opened, is also modified upon saving the form.