Creatio development guide
PDF
This documentation is valid for Creatio version 7.10.0. We recommend using the newest version of Creatio documentation.

Adding a new rule for the case deadline calculation

Glossary Item Box

General information

Bpm'online enables implementation of the custom logic for obtaining time parameters for calculating the case deadlines. The strategy implemented by the developer will be used instead of one of the base strategies in the calculation or recalculation of the case deadlines.

The rules are selected from the [Case deadline calculation schemas] lookup. To add a new calculation rule:

1. Create the object schema, add columns for the estimated response time and resolution time and links for the calendar, service agreements and services.

2. Create a lookup based on this schema, fill it with the values for the deadline calculation.

3. Add the source code schema, declare there a class inherited from the BaseTermStrategy abstract class. Implement custom mechanism of getting the response and resolution time parameters of the case.

4. Connect a new rule.

Case description

Add custom rule for the calculation of the time parameters of the case for the [Lost data recovery] service according to the [78 – Elite systems] service agreement. Specify the following values for the new rule:

  • Response time – 2 calendar hours;
  • Resolution time – 1 working day;
  • Calendar – [Default calendar].

Case implementation

1. Create an object schema with the columns for calculation

For this, select the custom package in the [Configuration] service on the [Schemas] tab execute the [Add] > [Object] command (Fig. 1, 1).

Fig. 1. Adding the schema

You need to assign the following properties for the created object schema (Fig. 2):

  • [Name] – "UsrServiceTestTerms";
  • [Title] – "ServiceTestTerms";
  • [Package] – the user package where the development is taking place, for example the Custom package;
  • [Parent object] – the [BaseEntity] schema of the Base package.

Fig. 2. The properties of the added object schema

For the created schema, create the columns with the properties as specified in the table 1.

Table 1. The properties of the added columns

Name Header Type Details
UsrReactionTimeUnit Response time unit [Time unit] lookup Specifies the time unit (calendar days, hours, etc.) that will be used for the [Response time] calculation.
UsrReactionTimeValue Response time Integer A column for the response time value.
UsrSolutionTimeUnit Resolve time unit [Time unit] lookup Specifies the time unit (calendar days, hours, etc.) that will be used for the [Resolution time] calculation.
UsrSolutionTimeValue Resolution time Integer A column for the resolution time value.
UsrCalendarId Calendar that is used [Calendar] lookup A calendar that will be used in the calculation of the case deadlines.
UsrServicePactId Service agreement [Service agreement] lookup A link to the [Service agreement] object. Added for the filtering purposes.
UsrServiceItemId Service [Service] lookup A link to the [Service] object. Added for the filtering purposes.

 Publish the object schema after adding the columns.

2. Create a lookup; fill it with the values for the deadline calculation

Set the exact values of the response and resolution deadlines for their calculation. For this, create the lookup based on the created schema with following properties (Fig. 3):

  • [Name] – “Custom response and resolution deadlines”;
  • [Object] – ServiceTestTerms.

Fig. 3. The properties of the added lookup

 

Add at least one record in the lookup. Add the following data according to case conditions (Fig. 4):

Fig. 4. A record in the added lookup that meets the case conditions

 

3. Implement the class with the mechanism of getting the time parameters

Add the source code schema (Fig. 1, 2). Add a class inherited from the BaseTermStrategy abstract class declared in the Calendar package to the schema source code. Implement a parameterized constructor in the class, with the following parameters:

  • UserConnection userConnection – current user connection;
  • Dictionary<string, object> args – the arguments for the calculation.

Implement the GetTermInterval() abstract method that is declared in the base class. This method receives the mask of the filled values as an input parameter. The decision to fill exact time parameter of the TermInterval class that implements the ITermInterval<TMask> interface is based on this mask.

The schema source code:

namespace Terrasoft.Configuration
{
    using System;
    using System.Collections.Generic;
    using Terrasoft.Common;
    using Terrasoft.Configuration.Calendars;
    using Terrasoft.Core;
    using Terrasoft.Core.Entities;
    using CalendarsTimeUnit = Calendars.TimeUnit;
    using SystemSettings = Terrasoft.Core.Configuration.SysSettings;
    public class ServiceTestTermsStrategy: BaseTermStrategy<CaseTermInterval, CaseTermStates>
    {
        // A container class for storing data received from an entry point.
        protected class StrategyData
        {
            public Guid ServiceItemId {
                get;
                set;
            }
            public Guid ServicePactId {
                get;
                set;
            }
        }
        //A field that stores data from the entry point.
        protected StrategyData _strategyData;
        // Parameterized constructor, for correct
        // initialization by a class-selector.
        public ServiceTestTermsStrategy(UserConnection userConnection, Dictionary<string, object> args)
            : base(userConnection) {
            _strategyData = args.ToObject<StrategyData>();
        }
        // A method that receives data and returns it in an instance of the CaseTermInterval class. 
        public override CaseTermInterval GetTermInterval(CaseTermStates mask) {
            var result = new CaseTermInterval();
            // Create an EntitySchemaQuery query.
            var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "UsrServiceTestTerms");
            // Adding columns to a query.
            string reactionTimeUnitColumnName = esq.AddColumn("UsrReactionTimeUnit.Code").Name;
            string reactionTimeValueColumnName = esq.AddColumn("UsrReactionTimeValue").Name;
            string solutionTimeUnitColumnName = esq.AddColumn("UsrSolutionTimeUnit.Code").Name;
            string solutionTimeValueColumnName = esq.AddColumn("UsrSolutionTimeValue").Name;
            string calendarColumnName = esq.AddColumn("UsrCalendarId.Id").Name;
            // Adding filters to a query.
            esq.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrServiceItemId", _strategyData.ServiceItemId);
            esq.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrServicePactId", _strategyData.ServicePactId);
            // Executing and processing query results.
            EntityCollection entityCollection = esq.GetEntityCollection(UserConnection);
            if (entityCollection.IsNotEmpty()) {
                // Addition to the return value of the reaction time.
                if (!mask.HasFlag(CaseTermStates.ContainsResponse)) {
                    result.ResponseTerm = new TimeTerm {
                        Type = entityCollection[0].GetTypedColumnValue<CalendarsTimeUnit>(reactionTimeUnitColumnName),
                        Value = entityCollection[0].GetTypedColumnValue<int>(reactionTimeValueColumnName),
                        CalendarId = entityCollection[0].GetTypedColumnValue<Guid>(calendarColumnName)
                    };
                }
                // Adding to the returned value of resolve time.
                if (!mask.HasFlag(CaseTermStates.ContainsResolve)) {
                    result.ResolveTerm = new TimeTerm {
                        Type = entityCollection[0].GetTypedColumnValue<CalendarsTimeUnit>(solutionTimeUnitColumnName),
                        Value = entityCollection[0].GetTypedColumnValue<int>(solutionTimeValueColumnName),
                        CalendarId = entityCollection[0].GetTypedColumnValue<Guid>(calendarColumnName)
                    };
                }
            }
            return result;
        }
    }
}

Publish the schema after adding the source code.

4. Connect the new rule

For this, add the value in the [Case deadline calculation schemas] lookup. Specify the full qualified name of the created class in the [Handler] column (including the namespace).

In the [Alternative schema] column you can specify the deadline calculation rule used when the deadline calculation with current schema is impossible. Note that the alternative schema class will be created if any of time parameters is not calculated by the strategy class. If the alternative schema cannot calculate the deadline, then its alternative strategy instance will be created. The queue of rules is formed in this way.

Check the [Default] checkbox at adding new record.

The example of adding the record to the [Case deadline calculation schemas] lookup (Fig. 5).

Fig. 5. The record of the custom deadline calculation rule

 

As a result, the new rules of the deadline calculation will be applied for the cases of the [78 – Elite systems] service agreement for the [Lost data recovery] service (Fig. 6).

Fig. 6. Case result

 

 

© bpm'online 2002-2017.

Did you find this information useful?

How can we improve it?