Working with data fields

Introduction to data fields

The access to data fields is an essential part of ConSol CM programming. It is potentially required in all scripts of the system, workflow as well as Admin Tool scripts, no matter of which type. Here, we will set the focus on workflow programming, but the access to data fields is basically the same in all scripts.

There are three types of data fields:  

Rules for work with data fields

When you work with ticket fields, customer fields or resource fields, there are two main rules you have to keep in mind:

  1. All data fields are always managed and referenced in data field groups, e.g. when you want to retrieve the value of a ticket field, you use e.g., <ticket field group name>.<ticket field name>
  2. You always use the technical unique name to reference a data field group or a data field, not the localized value.

Data types for data fields

A data field is always of a certain data type. As for any variable in programming, it depends on the data type how you have to handle the value of the field, e.g. a string field cannot be used for calculating numbers, an enum field needs a specific access method.

The following data types are available for ticket fields, customer fields and resource fields.

The data type you choose on creating a data field cannot be changed afterwards!

Details about string fields: use annotations to fine-tune strings

String fields are widely used for customer, ticket, and resource data and strings can be used to contain various content, for example, a text box with a comment, a simple input field with only 20 characters, a URL or a password. The fine-tuning of string fields is implemented using specific annotations which are all listed on the Annotations page. However, since work with these annotations is an every-day task of CM administrators, the most important and most commonly used annotations will be explained here as well.

How can I ...

... insert a text box instead of a single line?

Value for annotation text-type: textarea

The size of the text box can be adjusted, displayed as standard text box depending on web browser. Use the field-size annotation in case a specific size of the text box is required.

... hide the input of the fields for passwords?

Value for annotation text-type: password

Only dots will be displayed. This annotation does not define the field to contain a password! It only defines the display mode! Use the password annotation to define a string field to contain the CM/Track password.

... display a hyperlink, display the name instead of the link?

Value for annotation text-type: url

Input will be displayed as a hyperlink in view mode. String has to match a specific URL pattern:

First part of the string is the link (url), second part is the name which should be displayed.

Example: "http://consol.de ConSol"

... display a file link?

Value for annotation text-type: file-url

Input will be displayed as a link to a file on the file system. The web browser has to allow/support those links!

Example: Enabling file:// URLs in a Firefox browser

Add the following lines to either the configuration file prefs.js or to user.js in the user profile. On a Windows system usually in a folder like C:\Users\<USERNAME>\AppData\Roaming\Mozilla\Firefox\Profiles\uvubg4fj.default

Alternatively a Firefox browser add-on like Local Filesystem Links can be installed for better access to the referenced files and folders.

The link will also be displayed as tooltip.

The URL is correctly formed if the following conditions are met:

Example URLs:

See also the explanation about file-url in the section text-type

... define a label?

Value for annotation text-type: label

This will be a read-only field which is displayed in gray, use the label-group annotation to link label and input fields which belong together. Please take a look at the annotations for labels (show-label-in-edit, show-label-in-view) before implementing special label fields!

... define a field for the valid email addresses?

Value for annotation email: true

The field may only contain valid email addresses. Input will be validated according to standard email format <name>@<domain>.

... define a scripted autocomplete list? 

Value for the annotation text-typeautocomplete

Optional: value for the annotation autocomplete-script = <name of the respective script>

A scripted autocomplete list is used to provide a drop-down menu which is filled dynamically using the input the engineer has provided so far. For example, when the user types "Mil", the possible values "Miller", "Milberg", and "Milhouse" are displayed as list and the engineer can select the one required for the field. You know this behavior from other autocomplete fields, e.g., the search for engineers for a ticket or the search for customers while creating a ticket. However, in these cases, CM generates the list automatically. The behavior cannot be influenced or customized. Scripted autocomplete lists, on the contrary, can be implemented by the CM administrator. The values are based on a result set which is dynamically created. The result set can contain strings, engineers, customers (Units), and resources.

A detailed description of scripted autocomplete lists is provided in section Scripted Autocomplete Lists in the Administrator Manual.

... define a field for the CM/Track login?

Value for annotation username: true

Will be used for authentication against CM/Track server. Only for customer fields in a contact object.

... define a field for the CM/Track password?

Value for annotation password: true

Will be used for authentication against CM/Track server (in DATABASE mode). Only for customer fields in a contact object.

... define a field containing personal data?

Value for annotation personal-data: true

This annotation can be assigned to ticket and contact fields. Contact fields with this annotation will be deleted when a contact is anonymized. Ticket fields with this annotation will be deleted when the main customer of the ticket is anonymized.

When defining a field to contain personal data, please take into account that the deletion of the field during the anonymization process is treated as a regular update. Therefore, business event triggers reacting on changes to ticket fields fire, and the contact update action script is executed.

This might lead to unwanted side-effects.

... define a rich text field?

Create a field of the type long string.

Value for the annotation string-content-type: html-inline (field content is directly displayed on the GUI in view mode) or html-link (field content is displayed in a pop-up window after clicking the Show content link in view mode)

A rich text field can contain images and formatted text. In the edit mode, it features a basic editor.

Methods for accessing data fields

The basic methods for accessing data fields are the same for tickets, customers and resources. The following sections provide a short introduction to each object type and describe the available methods.

Ticket data

In the Admin Tool, the ticket fields are defined in the navigation group Tickets, navigation item Ticket Fields.

Figure 118: ConSol CM Admin Tool - Ticket field administration for ticket data

You need four methods of the class Ticket to work with ticket fields:

See section Coding examples with different data types for details about handling the different field types.

Customer data

The customer data model contains customer field groups and customer fields. They are both defined in the Admin Tool, navigation group Customers, navigation item Data Models.

Figure 119: ConSol CM Admin Tool - Customer field administration for customer data

You need four methods of the class Unit to work with customer fields:

Alternatively, you can separate the field group name and the field by a colon.

See section Coding examples with different data types for details about handling the different field types.

When working with customer data, you also need access to the different customer objects. The following examples show the convenience methods provided by the ConSol CM API for this purpose.

It is possible to chain the methods, for example to get the number of tickets of the first contact of a company:

Integer count = contact.get("company().contacts()[0].tickets()[count]");

Coding examples using the ConSol CM Action Framework are provided in the ConSol CM Administrator Manual, section Scripts for the Action Framework.

Resource data

The optional module CM/Resource Pool allows to extend the CM database and store resource objects. These can be various objects like IT assets, contracts, shop items or whatever is required in the respective company. The resource data model is defined in the navigation group Resources, navigation item Data Models of the Admin Tool.

Figure 120: ConSol CM Admin Tool - Definition of the resource data model

You need four methods of the class Resource to work with resource fields:

See section Coding examples with different data types for details about handling the different field types.

When programming with resources it is often required to retrieve the resources which are linked to a certain ticket or customer. This topic is treated in detail in the section Working with resource relations.

Coding examples using the ConSol CM Action Framework are provided in the ConSol CM Administrator Manual, section Scripts for the Action Framework.

Coding examples with different data types

The following section shows examples of working with data fields of different data types. The examples refer to ticket fields. Nevertheless, the handling is the same for customer and resource fields. The fields are always referenced by their technical names using the following pattern:

<ticket|unit|resource>.<get|set|add|remove>("<technical name of the field group>.<technical name of the field>")

Simple data types

Simple data types are data fields which contain a single value or object. The following list shows the available simple data types with the classes of their values:

Retrieving and setting simple field values

The following example shows how to retrieve a boolean value of a ticket field to use it in a precondition script:

boolean vip_info = ticket.get("am_fields.vip")

 

if(vip_info == true){

return true

}

else {

return false

}

Code example 29: Precondition script where a boolean value is checked

The same behavior can be achieved by directly returning the value:

return ticket.get("am_fields.vip")

Code example 30: Precondition script where a boolean value is checked, short version

The following example shows how to set a value in a ticket field. As the field has the data type date, it requires a Date object, which can be created directly in the statement.

ticket.set("fields.reaction_time", new Date());

Code example 31: Setting a ticket field value for a field of type Date

When you work with number or date fields, you can even calculate with the field values in a very comfortable way, see following example.

ticket.add("fields.orders_number", 1)

Code example 32: Adding one to the number of orders

Retrieving and setting enum values

An enum (sorted list) field is a field where the value is one of various list values. For example, a list with priorities is the basis for an enum field. To retrieve the value of an enum field, you can use the same syntax as for simple data types. The get method provides an object of the class EnumValue. Use the getName() method to retrieve the string with the technical name of the value. The .name notation is the Groovy version of the getter method.

def prio = ticket.get("helpdesk_standard.priority")

log.info 'Priority is now ' + prio.getName()

//or shorter:

log.info 'Priority is now ' + prio.name

Code example 33: Retrieving an enum value for a ticket field

If you want to retrieve the localized value of an enum, you have to use LocalizationService.

def my_enum_field = ticket.get("helpdesk_standard.priority")

def my_enum_field_localized = localizationService.getLocalizedProperty(EnumValue.class, "name", my_enum_field.id, engineerService.getCurrentLocale())

To set an enum value, use the technical value with the following syntax. The new value has to be present in the enum which is referenced by the ticket field.

ticket.set("helpdesk_standard.priority", "URGENT");

Code example 34: Setting an enum value

Retrieving MLA values and paths

The Java class for MLAs (Multi Level Attributes) is MultiEnumField. MLAs are handled like regular enums when it comes to retrieving and setting values.

The following examples show the basic methods:

The following example shows how to retrieve the entire path to the selected MLA value: 

List<EnumValue> mlaPathElements = mlaService.getAssignedMla(ticket, "helpdesk_standard", "categories")

def mlaPath1=""

mlaPathElements.each() {elem ->

mlaPath1 = elem.name + ' -- ' + mlaPath1

}

 

//or shorter:

def mlaPath2 = mlaService.getAssignedMla(ticket, "helpdesk_standard", "categories").reverse()*.name.join(" -- ")

Code example 35: Retrieving the entire path to the selected MLA value

Lists and tables

Lists and tables are “containers” for other data fields. A data field of the type list contains either one field of a simple data type or a struct which consists of several fields of simple data types. A list field can contain several values.

Lists

Each line of a list contains a value of a simple data type, a date in our example. The ticket field of type date has to have the parameter Belongs to which points to the list.

Figure 121: ConSol CM Admin Tool - Ticket fields for a list of date fields

Figure 122: ConSol CM Web Client - List of date fields in a ticket (edit mode)

The most important methods for working with lists are shown in the following section using the list from the above example:

Tables (lists of structs)

The data construct list of structs is the technical basis for a multi-column table structure in the Web Client. The list is the parent object which contains lines. Each line is an instance of a struct. The struct contains as many data fields (table columns) as required. Please see the figures in the introductory part of this section.

To retrieve the data from a list of structs you can work with an iteration over the lines. In the following example, we work with a table where ...

Figure 123: ConSol CM Admin Tool - Ticket fields for a multi-column list (= table)

Figure 124: ConSol CM Web Client - Ticket with filled-in table

Fading in and out of data field groups

Data field groups can be faded in (made visible) and faded out (made invisible) depending on the process requirements. This helps to keep the objects concise, as the engineers only see the data fields which are relevant at the respective process stage.

A typical use case is a ticket field group which is invisible at first (ticket field group annotation group-visibility = false) and is faded in when the engineer needs to work with the data in the process. For example, a ticket field group which contains feedback of the customer is only displayed when the engineer has clicked the workflow activity Feedback received ... because this information is not needed before. In the same way, ticket field groups which are not required anymore can be faded out.

The following methods can be used for controlling the visibility of ticket field groups:

In addition, GroupPropertyType.VISIBLE can have the value open, which means that the tab of the field group in the Details section is selected/opened.

The same mechanism can be used for customers and resources. In these cases, the methods are:

Using data fields for variables

Sometimes it is necessary to work with variables which are required for workflow programming but should not be visible on the GUI. Depending on the object for which they are needed, you can use ticket, customer or resource fields for these variables.

Create the data fields with the required data type and make them invisible by assigning the annotation visibility = none.

If you want to control the values of the variables during the development stage, you can leave the field visible and assign the annotation once development is completed.