Adding a new rule for calculating case deadline
Glossary Item Box
Introduction
Bpm’online enables implementing custom logic of receiving parameters for calculating case deadline. When calculating or recalculating a case deadline, a developer implemented strategy is used instead of one of the base calculation strategies.
You can select a specific calculation rule in the [Case deadline calculation rules] lookup. Follow these steps to add a new calculation rule:
1. Create an object schema and add columns necessary for storage of response and resolution deadlines, links to the calendar, service agreement and service.
2. Based on the created object schema, add a lookup and populate it with values needed to calculate the deadline parameters.
3. Add the source code schema and declare the class inherited from the BaseTermStrategy abstract class. Implement custom mechanism of receiving response and resolution deadline parameters in the class.
4. Add a new rule.
Case description
Add a custom rule for calculating case deadline parameters for the [Lost data recovery] service as per the [78 — Elite Systems] agreement. Set the following values for the new rule:
- response time – 2 working hours
- resolution time – 1 working day
- used calendar – [Default calendar]
Source code of the case:
You can download the package with case implementation using the following link.
Case implementation algorithm
1. Creating an object schema containing the necessary columns for calculation
Perform the [Add] – [Object] action on the [Schemas] tab of the [Configuration] section.
Fig. 1. Adding the schema
Set the following properties for the created object schema (Fig. 2):
- [Name] – “UsrServiceTestTerms”
- [Title] – “ServiceTestTerms”
- [Parent object] – the [Base object] schema
Fig. 2. Properties of the added object schema
In the created schema, create a number of columns, whose primary properties are listed in table 1.
Table 1. Properties of the added columns
Name | Title | Type | Description |
---|---|---|---|
UsrReactionTimeUnit | Response time unit | The [Time unit] lookup | Specifies the time unit (calendar days, hours, etc.) that will be used for calculating the [Response time] parameter. |
UsrReactionTimeValue | Response time value | Integer | A column for storage the response time value. |
UsrSolutionTimeUnit | Response time unit | The [Time unit] lookup | Specifies the time unit (calendar days, hours, etc.) that will be used for calculating the [Response time] parameter. |
UsrSolutionTimeValue | Resolution time | Integer | A column for storage the response time value. |
UsrCalendarId | Calendar that is used | The [Calendar] lookup | The calendar used for calculating the case deadline. |
UsrServicePactId | Service agreement | The [Service agreement] lookup | Link to the [Service agreement] object. Added for enabling filtration. |
UsrServiceItemId | Service | The [Service] lookup | Link to the [Service] object. Added for enabling filtration. |
Publish the schema after adding the columns.
2. Adding a lookup and populating it with values needed to calculate the deadline parameters
Provide specific values to calculate the case response and resolution deadline. To do this, add a lookup with the following values based on the added schema (fig.3):
- [Name] – “Custom response and resolution deadlines”
- [Object] – ServiceTestTerms
Fig. 3. Properties of the added lookup
Add a record with the following data to the added lookup (as per the case conditions) (fig.4):
Fig. 4. A record in the created lookup that meets the case conditions
3. Implementing a class with the mechanism of receiving deadline parameters
Add the source code schema (fig.1, 2) Add the class inherited from the BaseTermStrategy abstract class (declared in the Calendar package) to the schema source code. Implement a parameterized constructor with the following parameters in the class:
- UserConnection userConnection – user current connection
- Dictionary<string, object> args – arguments that are the base of performing calculation
Implement the GetTermInterval() abstract method declared in the base class. This method accepts the mask of populated values as the incoming parameter, which is the base of taking a decision about populating the specific deadline parameters of the TermInterval returned class implementing the ITermInterval<TMask> interface.
The complete 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> { // Container class for storage of data received from the entrance point. protected class StrategyData { public Guid ServiceItemId { get; set; } public Guid ServicePactId { get; set; } } // The field for storage of data received from the entrance point. protected StrategyData _strategyData; // Parameterized constructor necessary for the correct // initialization by selector class. public ServiceTestTermsStrategy(UserConnection userConnection, Dictionary<string, object> args) : base(userConnection) { _strategyData = args.ToObject<StrategyData>(); } // Method that receives data and returns them in the CaseTermInterval class instance. public override CaseTermInterval GetTermInterval(CaseTermStates mask) { var result = new CaseTermInterval(); // Creating the EntitySchemaQuery query. var esq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "UsrServiceTestTerms"); // Adding columns to the 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 the query. esq.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrServiceItemId", _strategyData.ServiceItemId); esq.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrServicePactId", _strategyData.ServicePactId); // Execution and processing of query results. EntityCollection entityCollection = esq.GetEntityCollection(UserConnection); if (entityCollection.IsNotEmpty()) { // Adding response time to the nurtured value. 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 resolution time to the nurtured value. 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. Adding the new rule
Add a value to the [Case deadline calculation schemas] lookup. In the [Handler] column, specify the full qualified name of the created class (specifying the namespaces).
In the [Alternative schema] column you may specify the rule for calculating the deadline in case calculation by current rule is not possible. Take into considerations that if any of deadline parameters is not calculated by strategy class, a class instance of an alternative strategy will be created. In case the alternative strategy cannot calculate the deadline either, another alternative strategy will be created, thus forming a rule queue.
Select the [Default] checkbox for the added record.
See an example of an added record to the [Case deadline calculation schemas] lookup in fig.5.
Fig. 5. A record of a custom deadline calculation rule
As a result, new response and resolution deadline calculation rules will be applied for cases per the [78 — Elite Systems] agreement for the [Lost data recovery] service.
Fig. 6. Case result