Scripts of type Dependent enum

Dependent enums can be used in case, contact and resource data models. They allow to filter enumerated lists based on the values of other fields or any other criterion, e.g. the current queue or the user’s roles.

This allows to create hierarchical data structures. In contrast to hierarchical lists (see Hierarchical lists), the values of each level are calculated based on the value selected on the parent level. Therefore, instead of displaying all the values which belong to a given list, it is possible to display only a subset of the available list values. In addition, it is possible to have empty levels within a dependent enum. In the Web Client, the selected value on each level is displayed.

Steps to use a dependent enum script:

  1. Create the required lists on the Enumerated lists page, see Enumerated lists.
  2. Write a script of the type Dependent enum on the Scripts page.
  3. Assign the script to the desired data field group, see Data fields. A data field group can have several dependent enum scripts.

Coding example

The following example shows how to use a dependent enum script to determine the available enum values based on the queue:

import com.consol.cmas.common.model.customfield.dependentenum.DependentEnumMap

import com.consol.cmas.common.model.customfield.dependentenum.EnumFieldScriptContext

import static com.consol.cmas.common.model.customfield.dependentenum.DependentEnumScriptUtil.*

import static com.consol.cmas.common.model.customfield.dependentenum.DependentEnumEntryType.*

 

def getValuesForEnum(queueName) {

switch(queueName) {

case 'tickets':

return [

'normal',

'high',

]

break

case 'tasks':

return [

'low',

'normal'

]

break

default:

return [

'low',

'normal',

'high',

'critical',

]

break

}

}

 

def queueName = ticket.getQueueName()

 

def result = new DependentEnumMap()

def sourceGroupName = "myFieldGroup"

def sourceFieldName = "myDepEnumField"

def enumGroupName = "myEnum"

 

EnumFieldScriptContext myContext = new EnumFieldScriptContext(groupName:sourceGroupName,fieldName:sourceFieldName,enumGroup:enumService.getGroupByName(enumGroupName))

 

result[myContext.key] = getSelectedEnums(myContext,getValuesForEnum(queueName),FILLED)

 

return result

The following example shows how to use a dependent enum script to determine the available enum values based on the user’s roles:

import com.consol.cmas.common.model.customfield.dependentenum.DependentEnumMap

import com.consol.cmas.common.model.customfield.dependentenum.EnumFieldScriptContext

import static com.consol.cmas.common.model.customfield.dependentenum.DependentEnumScriptUtil.*

import static com.consol.cmas.common.model.customfield.dependentenum.DependentEnumEntryType.*

 

 

// example for use of service

// returns an array of technical enum value names

def getValuesDependingOnEngineerRole() {

displayValues = []

def rolesOfCurrentEngineer = engineerRoleRelationService.getRolesForEngineer(engineerService.current)

if(rolesOfCurrentEngineer.find{ it.name == 'user'}) {

displayValues += [

'low',

'normal',

]

}

if(rolesOfCurrentEngineer.find{ it.name == 'superuser'}) {

displayValues += [

'low',

'normal',

'high',

]

}

return displayValues

}

 

def result = new DependentEnumMap()

def sourceGroupName = "myFieldGroup"

def sourceFieldName = "myDepEnumField"

def enumGroupName = "myEnum"

 

EnumFieldScriptContext myContext = new EnumFieldScriptContext(groupName:sourceGroupName,fieldName:sourceFieldName,enumGroup:enumService.getGroupByName(enumGroupName))

 

result[myContext.key] = getSelectedEnums(myContext,getValuesDependingOnEngineerRole(),FILLED)

 

return result