Working with resource relations
Introduction
You can establish relations between resource objects and other objects using the module CM/Resource Pool. A resource relation can connect a resource to
- a ticket
- a customer (contact or company, i.e. a unit)
- another resource
Figure 137: Resource relation types
To be able to work with resource relations, you have to have a profound knowledge of the resource data model. Please refer to the ConSol CM Administrator Manual, section CM/Resource Pool for a detailed introduction.
The following Java classes are essential for working with resources, but of course they represent only a small subset of Java classes which form the Resource Pool. Please refer to the ConSol CM Java API Doc for a comprehensive description of all classes and methods.
Object |
Java class |
Admin Tool description |
Explanation |
---|---|---|---|
resource |
Resource |
Resource |
An object of the defined Resource Type. |
resourceRelationService |
Interface ResourceRelationService |
- |
the service which offers a lot of helpful methods for dealing with resources |
ResourceRelation xy |
ResourceRelation |
Resource (type) relation |
Relation between a resource and another object |
|
ResourceRelationWithTargetResourceCriteria ResourceRelationWithTargetTicketCriteria ResourceRelationWithTargetUnitCriteria |
- |
Stores the criteria which are the basis for a search, performed by the resourceRelationService |
Example: Calculating the reaction time of a ticket
A company can have a relation to a resource of type SLA. In this resource, SLA data are stored, e.g., the reaction time. The desired deadline for a service ticket is calculated by extracting the value of the reaction time from the resource object. With this value, the deadline for the service ticket is calculated and the result is entered in the Desired deadline data field of the ticket.
import com.consol.cmas.common.service.resource.*
import com.consol.cmas.common.model.resource.*
// if it is a clone - fill the respective custom field:
//Take SLA (resource) from company of main customer and calculate deadline from it
log.info('starting script in Set Parameters in ServiceDesk2 ...')
def maincust = ticket.mainContact
def unit_type = maincust.definition.type
log.info 'TYPE is now : ' + unit_type
def comp
if(unit_type == UnitDefinitionType.CONTACT) {
comp = maincust.get("company()")
} else if (unit_type == UnitDefinitionType.COMPANY){
comp = maincust
}
// find SLA relation from SLA resource to the main customer (if company) or the company of the main customer (if contact)
def crit = new ResourceRelationWithTargetUnitCriteria()
crit.setUnit(comp)
crit.setResourceTypeName("SLAs")
List<ResourceRelationWithTargetUnit> myrelations = resourceRelationService.getByCriteria(crit)
log.info 'myrelations size is now ' + myrelations.size()
if (myrelations.size() > 0) {
// one unit can have only one SLA as relation, see AT definition
def my_sla = myrelations[0].getSourceResource()
def sla_name = my_sla.get("SLA_Fields_basic.SLA_Name")
println 'SLA name is now ' + sla_name
def react_days = my_sla.get("SLA_Fields_basic.ReactionTime")
react_days = Integer.valueOf(react_days.intValue())
// calculate reaction time
def now = new Date()
def deadline = now + react_days
ticket.set("serviceDesk_fields.desiredDeadline",deadline)
}
Code example 60: Calculate ticket deadline from SLA. SLA as resource which is linked to the ticket.