Scripts for the Action Framework

Introduction

The ConSol CM Action Framework offers the ability to start actions which are not related to workflow activities, i.e., they can be started or triggered in another context, not only in a workflow context.

The Action Framework consists (as of ConSol CM version 6.10) of three components which are treated in the respective manual sections in detail.

In this section here, you will learn more about Action Framework-specific programming.

Admin Tool Scripts for the Action Framework

Script Types

Each action is based on an Admin Tool script as described in the sections mentioned above. For each Admin Tool script, the correct script type has to be set.

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

Thus, the execution script will only be executed if either

or

The following Action Framework-related script types are available:

Script Return Values

The return value of a condition script has to be either true or false.

The return value of a manual execution script has to be one of the following PostActionTypes:

Please see the details in the following section.

Action Types

An action can be of one of the following types:

Programming with the Action Framework

One core component of programming scripts for manual actions in the ConSol CM Action Framework is the class ActionScriptResultFactory. An instance of this class is available as actionScriptResultFactory in each execution script. The type of the returned PostActionScriptResult, i.e., the PostActionType, defines the step directly following the execution of a manual execution script. You can implement the desired system behavior using the PostActionType.

Open the Create Ticket Page

Example:

import com.consol.cmas.core.server.service.action.PostActionType

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

ticket.set("queue_fields", "boolean", "true")

return actionScriptResultFactory.getPostAction(PostActionType.CREATE_TICKET, ticket)

//to additionally set main contact use

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

Code example 67: Open the Create ticket page

Open the Ticket Page in Display-Only Mode

Example:

UnitCriteria unitCriteria = new UnitCriteria();

Unit companyPattern = new Unit("company", customerGroup);

mdcmCriteriaBuilder.setReferencedCompanyCriteria(unitCriteria, companyPattern);

Code example 68: Open the ticket page in display mode

Open the Ticket Page in Display-Only Mode and Show ACF Before

Example:

(...)

 

def executionContext = activityFormDefinitionService.getExecutionContext(newtic, "defaultScope/TaskInProgress/AcceptTask")

if (!executionContext) {

return actionScriptResultFactory.getPostAction(PostActionType.FAILURE, "action.fail.wrong.activity")

}

 

// Modify entities from the execution context - not the original ones

// - since the user may still press cancel.

executionContext.ticket.add("SpecialTasks_Fields","Deadline", new Date());

 

return actionScriptResultFactory.getPostAction(PostActionType.GOTO_TICKET, newtic, executionContext);

Code example 69: Open the ticket page in display mode and show ACF before

Please note that the implementation class for the bean activityFormDefinitionService is ActivityControlFormService. Please refer to the class documentation for details. In scripts, access is by its bean name, as in the script above.

Open the Create Unit (Contact or Company) Page

Example:

import com.consol.cmas.common.model.customfield.Unit

import com.consol.cmas.core.server.service.action.PostActionType

 

Unit contact = new Unit("customer", unit.getCustomerGroup());

contact.set("firstname", "Luke");

contact.set("name", "Skywalker");

return actionScriptResultFactory.getPostAction(PostActionType.CREATE_UNIT, contact);

Code example 70: Unit execution script (customer implicitly available) to open the Create customer page

Open a Unit (= Customer, i.e., Contact or Company) Page in Display-Only Mode

Example:

import com.consol.cmas.common.model.customfield.Unit

import com.consol.cmas.core.server.service.action.PostActionType

 

Unit contact = unitService.getByCustomerGroup(unit.getCustomerGroup()).get(0)

return actionScriptResultFactory.getPostAction(PostActionType.GOTO_UNIT, contact)

Code example 71: Unit execution script (unit implicitly available) to open a customer page in display mode

Open a Create Resource Page

Example:

import com.consol.cmas.common.model.resource.Resource

import com.consol.cmas.common.model.resource.meta.ResourceType

import com.consol.cmas.core.server.service.action.PostActionType

 

ResourceType type = resourceTypeService.getByName("resource type 1")

Resource resource = new Resource(type)

resource.setFieldValue("group1", "stringField1", "value1")

resource.setFieldValue("group2", "numberField1", 1L)

return actionScriptResultFactory.getPostAction(PostActionType.CREATE_RESOURCE, resource)

Code example 72: Open a Create resource page

Open a Resource Page in Display-Only Mode

Example:

import com.consol.cmas.common.model.resource.Resource

import com.consol.cmas.core.server.service.action.PostActionType

 

Resource resource = resourceService.getAll().iterator().next()

return actionScriptResultFactory.getPostAction(PostActionType.GOTO_RESOURCE, resource);

Code example 73: Open a resource page in display mode

Open a URL

Example:

import com.consol.cmas.core.server.service.action.PostActionType

 

return actionScriptResultFactory.getPostAction(PostActionType.GOTO_PAGE, "http://consol.de");

Code example 74: Open a URL

Display Result Message in Web Client: SUCCESS

For details, please refer to section Return Values and Return Messages.

Display Result Message in Web Client: FAILURE

For details, please refer to section Return Values and Return Messages.

Return Values and Return Messages

To indicate the return value of a ConSol CM action for the engineer in the Web Client, you have to use one of two PostActionTypes:

You have to set a return value for every execution script. It is not possible to end an execution script without the return value (a run-time error will be thrown in that case).

Example of a positive feedback:

return actionScriptResultFactory.getPostAction(PostActionType.SUCCESS, "cmweb.search.assigned").withRefreshContent();

Figure 409: ConSol CM Web Client - SUCCESS message after Search (Result) Action

Example of a negative feedback:

return actionScriptResultFactory.getPostAction(PostActionType.FAILURE, "cmweb.search.assigned").withRefreshContent();

Figure 410: ConSol CM Web Client - FAILURE message after Search (Result) Action

The text which is displayed (e.g., Action succeed or Action failed) can be retrieved using one of two methods:

CM Standard Values for Return Messages

action.result.success=Action succeeded

action.result.failure=Action failed

Use System-Specific Labels

You can define your own labels for the display of messages in the Web Client. See section Labels for a detailed explanation.

Working with Relation Actions

Relation actions are available in CM versions 6.10.5.4 and up. They are available for all three main object types and are defined in the Admin Tool for the navigation items. 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 when 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 object are available: 

Please note that in CM version 6.10.5.4, it is not possible within the relation action script to distinguish between a CREATE and a DELETE operation.

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.

Steps to perform:

  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 execution 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

log.info 'SLA to company relation action has been triggered!'

def myUnit = relation.targetUnit

def myUnitDef = relation.targetUnit.definition.name

log.info 'myUnitDef is ' + myUnitDef

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)

log.info 'customer name is ' + myCustName

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

if (contPersMail) {

log.info ' Email about SLA will be sent to ' + 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

def pText = "A relation has been modified 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 75: Relation action script to send an email when a resource-company relation has been created or deleted