Action Framework - Customer Actions

Introduction

Customer actions (also called Unit actions, previously called Data Object Actions) are system actions which are either triggered manually or by a certain incident concerning a customer, i.e. a customer is deleted or a customer is modified. Customer actions are components of the ConSol CM Action Framework. They can be performed for a customer, i.e., a contact or a company. The actions can be performed automatically by the system or manually, triggered by an engineer (via Web Client) who has the required permissions. You might want to apply customer actions for use cases like the following:

You can use the following types of customer actions:

Please keep in mind that only engineers who have at least one role with the following access permissions for the respective customer group are allowed to use the customer actions, i.e., only then will the Activities be displayed in the Web Client:

  • Act

Figure 137: ConSol CM Web Client - Example for manual customer activities

Customer actions are based on Groovy scripts which are stored in the Scripts and Templates section of the Admin Tool.

The execution of customer actions can be controlled using condition scripts, i.e., you can implement a customer condition script which is run before the action script of the customer action. The action script is only run if this condition script returns true.

So there are two types of scripts you have to deal with when you use the ConSol CM Action Framework:

When you want to implement a customer action you have to proceed in three steps:

  1. Create a script for the customer action (either an action script only or an action script and a condition script).
  2. Create the customer action(s) which use(s) the script(s).
  3. Assign the customer action(s) to the customer group(s) where they should be available. You can assign the actions to contacts and/or companies of a customer group.

In the following sections, all three steps are explained in detail.

Managing Customer Actions Using the Admin Tool

In this book we will use the terms customer and customer definition. In previous versions of ConSol CM, the term data object was used to refer to customers. However, the names of the corresponding Java classes are Unit and UnitDefinition. All other Java classes which deal with customer objects are also still named Unit... Please keep that in mind if you work as both a ConSol CM administrator and programmer. Please refer to the ConSol CM Java API Doc for details.

Step 1: Write the Customer Action Script

Create a new Admin Tool script of type Customer action. If required, create another script of type Customer condition.

For a detailed explanation of Admin Tool scripts, please refer to section Admin Tool Scripts. For an introduction to Admin Tool scripts used for customer actions, please read section Scripts for the Action Framework: Programming Customer Actions in this chapter.

Figure 138: ConSol CM Admin Tool - System, Scripts and Templates: Scripts for customer actions

// display Create Ticket page for a new Service Desk ticket

 

def newticket = new Ticket()

def qu = queueService.getByName("ServiceDesk")

newticket.setQueue(qu)

client.goToCreateTicket(newticket).withCustomer(unit)

Code example 9: Script which opens the create ticket page with the customer as the main customer, CM version 6.11 and up

Step 2: Create Customer Action(s) Which Use the Script

Open the navigation item Actions in the navigation group Customers in the Admin Tool and add (= create) a new action object using the Add button . The same pop-up window appears for both adding and editing a customer action.

Figure 139: ConSol CM Admin Tool - Customers, Actions: Editing a customer action

In the pop-up window, the parameters for the new action have to be defined:

Save the action. You can then assign it to customer groups, as described in the following step.

Step 3: Assign Customer Actions to Customer Groups

For the customer action to become effective, you have to assign it to a customer group, at which point it will be available for all customers of this customer group. Depending on the initial definition (contact or company action), the action will be available for contacts or for companies in the customer group. To assign a customer action to a customer group, open the navigation item Customer Groups in the navigation group Customers of the Admin Tool. Select the customer group you would like to edit and click the Edit button to open the pop-up window to assign the customer actions. All customer actions which have been stored under Actions (see step 2) will be available here, each for the corresponding action type. For example, an action which has been defined for the type Update during definition (see step 2) will only be available as an Update action.

Figure 140: ConSol CM Admin Tool - Customers, Customer Groups: Assigning customer actions to a customer group

You can assign the following action types to a customer group:

Using Customer Actions as an Engineer (User)

As an engineer (user), only the customer action type manual is relevant for you. The CREATE, UPDATE and DELETE scripts run in the background.

Manual actions are offered in the Web Client, similar to workflow activities for a ticket. Please see Example 1 in the next section.

Examples for Customer Action Scripts

Example 1: Simple Manual Action

A manual action is coded and stored as an Admin Tool script, then a company action is defined using the script, and the action is assigned to a customer group.

Figure 141: ConSol CM Admin Tool - System, Scripts and Templates: Customer action script for a company action

Figure 142: ConSol CM Admin Tool - Customers, Actions: Defining the company action

Figure 143: ConSol CM Admin Tool - Customers, Customer Groups: Assigning a company action to a customer group

The engineer can use the action manually in the Web Client.

Figure 144: ConSol CM Web Client - Using a manual company action

A script similar to the following could be used:

// ... do something, e.g., reference an external system to find the current service status of the company) ...

 

def ser_stat = enumService.getValueByName("service_status","ok")

 

// set the new service status for the company

if (ser_stat.name == "ok") {

unit.set("ResellerCompanyData:service_status","ok")

client.showInfoMessage("info.dataobject.action.success").withRefreshContent();

}

Code example 10: Customer action script, CM version 6.11 and up

Example 2: New Ticket for a Customer

The following script opens the Create ticket page for the contact or company the action was performed for. The target queue is ServiceDesk, enabling a new Service Desk ticket to be created in no time for the open contact or company. For an introduction to Admin Tool scripts for the Action Framework, please read the following section.

// display Create Ticket page for a new Service Desk ticket

 

def newticket = new Ticket()

def qu = queueService.getByName("ServiceDesk")

newticket.setQueue(qu)

client.goToCreateTicket(newticket).withCustomer(unit)

Code example 11: Script which opens the create ticket page with the customer as the main customer, CM version 6.11 and up

Please note that in case a ticket should be created with a company as main customer, the checkbox Company as customer must be checked for the customer data model of the respective customer group.

Scripts for the Action Framework: Programming Customer Actions

Customer actions are defined by Admin Tool scripts, i.e., by Groovy scripts which are stored in the Scripts and Templates section of the Admin Tool. The predefined object unit (i.e., an object of class Unit) is available for those scripts. Objects of the class Unit can represent a company or a contact, depending on the context.

There are two types of scripts for the Action Framework:

Customer Action Scripts

The actions in this script are either triggered automatically by the system operations CREATE, UPDATE, or DELETE or by a manual action of the engineer (using Activities in the Web Client).

Automatic Customer Action Scripts

unit.set("personalData.name", "Skywalker")

unitService.update(unit)

Code example 12: Set a value in customer data and update the unit

When you use unitService.update(unit), as in the example above, you should use a customer condition script to avoid infinite loops. See the notes in section Customer Condition Scripts.

Manual Customer Action Scripts

For manual customer action scripts you can use the methods of the object client (class OperationResponseBuilder) to determine the behavior of the Web Client after the action script is executed. The following list shows some examples, you can find the complete list of available methods in Overview of the Methods.

Create a Customer

Use the method client.goToCreateUnit(unit) to open the page to create a new customer. You need to create a new unit object and provide the customer group and customer definition. Optionally, you can pre-fill some data.

// 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", "Han")

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

 

client.goToCreateUnit(myunit)

Code example 13: Company script which fills some customer data, CM version 6.11 and up

Figure 145: ConSol CM Web Client - Manual company action

Figure 146: ConSol CM Web Client - Create customer page opened and pre-filled by company action

Of course, the names of the customer fields which are used in the script have to be the ones from the customer data model which has been assigned to the customer group for which a new contact should be created.

Figure 147: ConSol CM Admin Tool - Customers, Data Models: Script for creating contact as company action

Create a Ticket

Use the method client.goToCreateTicket(ticket) to open the page to create a new ticket. You need to create a new ticket object and provide the queue. Optionally, you can pre-fill some data. If you want to set a customer for the ticket, you can append the method withCustomer(unit). In the example below, unit is the customer on whose page the action is executed.

// display Create Ticket page for a new Service Desk ticket

 

def newticket = new Ticket()

def qu = queueService.getByName("ServiceDesk")

newticket.setQueue(qu)

client.goToCreateTicket(newticket).withCustomer(unit)

Code example 14: Script which opens the create ticket page with the customer as the main customer, CM version 6.11 and up

Please remember that the customer group for which the script should be applied has to be assigned to the queue where the ticket is to be created (ServiceDesk in the example).

Figure 148: ConSol CM Web Client - Manual contact action

Figure 149: ConSol CM Web Client - Create ticket page opened and pre-filled by contact action

Open a Customer Page

Use the method client.goToUnit(unit) to open a customer page. In the example below, unit is the Reseller company which is responsible for the end customer. A company-contact relation has to be set before. If more than one reseller relation has been defined, the first relation in the list is used.

Figure 150: ConSol CM Web Client - Customer action on contact detail page (activity opens company detail page of responsible reseller, CM version 6.11)

// Open company detail page of responsible reseller company, is only executed if this relation exists (checked in a condition script)

 

def unit_rel_def = unitRelationDefinitionService.getByName("ResellerDirectCustomersRelation")

Set<UnitRelation> res_relations = unitRelationService.getByDefinitionAndTarget(unit_rel_def, unit)

 

if (res_relations.size() > 0) {

def source_unit = res_relations.toArray()[0].getSourceUnit()

client.goToUnit(source_unit)

}

Code example 15: Script which opens the company page, CM version 6.11 and up

If the action OpenResponsibleResellerPage should only be displayed in the Web Client when a relation to the responsible reseller has been set, you can work with a customer condition script. It has to be created as an Admin Tool script of type Customer condition and has to be assigned to the customer action in the Actions section.

Figure 151: ConSol CM Admin Tool - Customers, Actions: Assignment of customer condition script

// Checks if reseller relation is set

 

def unit_rel_def = unitRelationDefinitionService.getByName("ResellerDirectCustomersRelation")

Set<UnitRelation> res_relations = unitRelationService.getByDefinitionAndTarget(unit_rel_def, unit)

if (res_relations.size() > 0) {

return true

} else {

return false

}

Code example 16: Customer condition script which checks if reseller relation is present

Open a Ticket Page

Use the method client.goToTicket(ticket) to open a ticket page. In the example below, ticket is the first ticket in the list of account management tickets which have the current company as a main customer.

//get tickets in Account Management queue with the current company as main customer

 

def myqueue = workflowApi.getQueueByName("AccountManagement")

def tickets1 = ticketService.getByQueue(myqueue)

def tickets2 = ticketService.getByMainContact(unit)

 

def foundTickets = tickets1.intersect(tickets2)

 

if ( foundTickets ) {

def AM_tic = foundTickets.first()

client.goToTicket(AM_tic)

}

Code example 17: Open a ticket page in view mode, CM version 6.11 and up

Figure 152: ConSol CM Web Client - Company action available on company page (1)

Figure 153: ConSol CM Web Client - AM page opened after company action Go to AM ticket

Open a Web Page

Use the method client.goToPage(string) to open a URL. In the example below, string is the URL saved in a company data field. You can also use this method to open a dynamically built URL.

// opens company's web site

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

 

if (!url) {

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

} else {

client.goToPage(url);

}

Code example 18: Script which opens a certain web site (URL), CM version 6.11 and up

The string error.script.no.url is a label which has been defined in the navigation group Labels, as described in section Labels.

Figure 154: ConSol CM Web Client - Company action available on company page (2)

Customer Condition Scripts

A customer condition script defines whether an action should be shown in the Web Client or not. It is executed before the customer action script. If it returns false, the customer action script will not be executed.

if(unit.getFieldValue("customer.personalData") == null) {

return true

} else {

return false

}

Code example 19: Customer condition script

To put a customer condition script into operation, you have to perform the following steps:

  1. Write an Admin Tool script of type Customer condition. The script has to define the conditions for the return values true and false, as demonstrated in the example above. At this point you must already know for which customer groups and data models the script will be used, to make sure you reference the correct data fields within the script.
  2. Assign the customer condition script to one or more customer action(s). This is done in the Actions section, navigation group Customers. Once in place, this specific customer condition script will always be executed before the customer action script of the same customer action.

That's it. You do not have to assign the condition script to a customer group. This happens implicitly when the respective customer action is assigned to contacts or companies of certain customer groups.

Important Groovy Objects

Object client

In all action scripts, the object client (class OperationResponseBuilder) is available to determine the behavior of the Web Client after the script is executed. It can be used, for example, to open a ticket page or to display a message.

Programming with the class OperationResponseBuilder is explained in detail in section Scripts for the Action Framework.

The customer actions Create, Update, and Delete are executed in the core methods create, update, and delete of the object unitService.

Thus, if the update action script updates the customer using the unitService.update(Unit) method then a java.lang.StackOverflowError error may be thrown because the update action will infinitely recurse. In that case a customer condition script should be used to avoid such infinite loops.

Working with the Changes Object in Customer Update Actions

Starting with CM version 6.10.5.4, it is possible to monitor the changes which have been performed during a customer update action. (The same applies to resource Update actions, explained in section Working with the Changes Object in Resource Update Actions).

To find out which changes have been performed use the object of class UnitChanges in Unit actions.

Please remember, the Update script will be executed:

There are two methods of the unitChanges object which provide information about the changed data: 

Since the method return parameters contain rather complex components, we recommend to read the API doc of the UnitChanges class. The following code provides an example for a script where a unitChanges object is used.

// Update Action Script UpdateContactData.groovy for contacts in Reseller group

import com.consol.cmas.common.model.content.unit.UnitCommentEntry

import com.consol.cmas.common.model.content.unit.UnitAttachmentEntry

log.info 'Contact data have been UPDATEd!'

// Are there any changes?

if (changes) {

log.info 'Yes, changes have been made to unit'

log.info 'Changes object is a ' + changes.class

}

// Have Custom Fields (Data object Group Fields) been changed? If yes - which?

if (changes.customFieldChangeInfo) {

log.info 'Yes, changes have been made to Custom Fields'

log.info changes.customFieldChangeInfo

log.info changes.customFieldChangeInfo.each { k, v ->

log.info "Changed field: ${k.groupName}/ ${k.fieldName}"

log.info "New value: ${v.value.value}"

log.info "Old value: ${v.previousValue.value}"

}

} else {

log.info 'No changes to Custom Fields'

}

 

// Have comments or attachmenst been changed? If yes - which?

log.info changes.contentChangeInfo

if (changes.contentChangeInfo){

log.info 'Yes, changes have been made in detail section'

if (changes.contentChangeInfo.value){

log.info changes?.contentChangeInfo.each { ctEntry ->

 

if (ctEntry?.value[0] instanceof UnitCommentEntry){

log.info 'A comment has been added.'

log.info 'Old value: ' + ctEntry?.previousValue

log.info 'New value: ' + ctEntry.value[0]?.text

log.info 'Made by the engineer ' + ctEntry.value[0]?.engineer?.name

log.info 'Creation date of the comment: ' + ctEntry.value[0]?.creationDate

} else if (ctEntry?.value[0] instanceof UnitAttachmentEntry){

log.info 'An attachment has been added.'

log.info 'Old value: ' + ctEntry?.previousValue

log.info 'New value text: ' + ctEntry.value[0]?.text

log.info 'New value file name: ' + ctEntry.value[0]?.filename

}

}

} else {

log.info 'Entry has been deleted.'

}

}

Code example 20: Unit Update script where changes are monitored and printed out to server.log

When for a contact in the customer group Resellers changes have been made to the two customer fields phone and vip_person, the following text is displayed in the server.log file.

database_UpdateContactData] [Susan-] Contact data have been UPDATEd!

database_UpdateContactData] [Susan-] Yes, changes have been made to unit

database_UpdateContactData] [Susan-] Changes object is a class com.consol.cmas.common.model.history.unit.UnitChanges

database_UpdateContactData] [Susan-] Yes, changes have been made to Custom Fields

database_UpdateContactData] [Susan-] {(phone,ResellerCustomerData)=Modification{value=AbstractField{key=(phone,ResellerCustomerData), value=0211/1231777}, previousValue=AbstractField{key=(phone,ResellerCustomerData), value=0211/1231666}}, (vip_person,ResellerCustomerData)=Modification{value=AbstractField{key=(vip_person,ResellerCustomerData), value=false}, previousValue=AbstractField{key=(vip_person,ResellerCustomerData), value=true}}}

database_UpdateContactData] [Susan-] Changed field: ResellerCustomerData/ phone

database_UpdateContactData] [Susan-] New value: 0211/1231777

database_UpdateContactData] [Susan-] Old value: 0211/1231666

database_UpdateContactData] [Susan-] Changed field: ResellerCustomerData/ vip_person

database_UpdateContactData] [Susan-] New value: false

database_UpdateContactData] [Susan-] Old value: true

Code example 21: Log output from the script above