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

Business rules in mobile application

Glossary Item Box

Introduction

Business rules represent a bpm’online mechanism that enables setting up the behavior of record edit page fields. You can use business rules to, e.g., set up visible or required fields, make fields enabled, etc.

ATTENTION

Business rules work only on record edit and view pages.

Adding business rules to a page is performed via the Terrasoft.sdk.Model.addBusinessRule(name, config) method, where

  • name – is the name of the model, bound to the edit page, e.g., “Contact”.
  • config – is the object defining business rule properties. The list of properties depends on a specific business rule type.

The base business rule

The base business rule is an abstract class, i.e., all business rules should be its inheritors.

The properties of the config configuration object that can be used by the inheritors of the business rule:

  • ruleType – the type of rule. The value must be included into the Terrasoft.RuleTypes enumeration.
  • triggeredByColumns – the column array that triggers the rule.
  • message – a text message displayed under the control element connected with the column in case business rule is not executed. It is necessary for rules that inform a user of warnings.
  • name – a unique name of a business rule. It is necessary if you need to delete a rule by the Terrasoft.sdk methods.
  • position – a position of a business rule that defines its order priority in the current queue.
  • events – an event array, defining the time of running business rules. It should contain values included into the Terrasoft.BusinessRuleEvents enumeration.

The Terrasoft.BusinessRuleEvents enumeration contains the following values:

  • Тerrasoft.BusinessRuleEvents.Save – the rule is executed before saving the data.
  • Terrasoft.BusinessRuleEvents.ValueChanged – the rule is executed when the data is modified (while editing).
  • Terrasoft.BusinessRuleEvents.Load – the rule is executed when the edit page is opened.

The [Is required] business rule (Terrasoft.RuleTypes.Requirement)

Defines whether an edit page field is required. Values of the config configuration object that are used:

  • ruleType – should contain the Terrasoft.RuleTypes.Requirement value for this rule.
  • requireType – verification type. The value must be included into the Terrasoft.RequirementTypes enumeration. The rule can verify one or all the columns from triggeredByColumns.
  • triggeredByColumns – the column array that triggers the rule. If the verification type equals Terrasoft.RequirementTypes.Simple, one column in the array should be specified.

The Terrasoft.RequirementTypes enumeration contains the following values:

  • Terrasoft.RequirementTypes.Simple – value verification in one column.
  • Terrasoft.RequirementTypes.OneOf – one of the columns specified in the triggeredByColumns should be populated.

Use case

Terrasoft.sdk.Model.addBusinessRule("Contact", {
    ruleType: Terrasoft.RuleTypes.Requirement,
    requireType : Terrasoft.RequirementTypes.OneOf,
    events: [Terrasoft.BusinessRuleEvents.Save],
    triggeredByColumns: ["HomeNumber", "BusinessNumber"],
    columnNames: ["HomeNumber", "BusinessNumber"]
});

The [Visibility] business rule (Terrasoft.RuleTypes.Visibility)

You can hide and display fields per condition using this rule. Values of the config configuration object that are used:

  • ruleType – should contain the Terrasoft.RuleTypes.Visibility value for this rule.
  • triggeredByColumns – the column array that triggers the rule.
  • events – an event array, defining the time of running business rules. It should contain values included into the Terrasoft.BusinessRuleEvents enumeration.
  • conditionalColumns – condition array of business rule execution. Usually, these are specific column values.
  • dependentColumnNames – column name array that the business rule is applied to.

Use case

Terrasoft.sdk.Model.addBusinessRule("Account", {
    ruleType: Terrasoft.RuleTypes.Visibility,
    conditionalColumns: [
        {name: "Type", value: Terrasoft.Configuration.Consts.AccountTypePharmacy}
    ],
    triggeredByColumns: ["Type"],
    dependentColumnNames: ["IsRx", "IsOTC"]
});

The fields connected with the IsRx and IsOTC columns are displayed if the Type column contains the value defined by the Terrasoft.Configuration.Consts.AccountTypePharmacy invariable.

Terrasoft.Configuration.Consts = {
    AccountTypePharmacy: "d12dc11d-8c74-46b7-9198-5a4385428f9a"
};

You can use the 'd12dc11d-8c74-46b7-9198-5a4385428f9a’ value instead of the invariable.

The [Enabled/Disabled] business rule (Terrasoft.RuleTypes.Activation)

This business rule enables and disables fields for entering values per condition. Values of the config configuration object that are used:

  • ruleType – should contain the Terrasoft.RuleTypes.Activation value for this rule.
  • triggeredByColumns – the column array that triggers the rule.
  • events – an event array, defining the time of running business rules. It should contain values included into the Terrasoft.BusinessRuleEvents enumeration.
  • conditionalColumns – condition array of business rule execution. Usually, these are specific column values.
  • dependentColumnNames – column name array that the business rule is applied to.

Use case

Whether a field connected with the Stock column is enabled depends on the value in the IsPresence column.

Terrasoft.sdk.Model.addBusinessRule("ActivitySKU", {
    ruleType: Terrasoft.RuleTypes.Activation,
    events: [Terrasoft.BusinessRuleEvents.Load, Terrasoft.BusinessRuleEvents.ValueChanged],
    triggeredByColumns: ["IsPresence"],
    conditionalColumns: [
        {name: "IsPresence", value: true}
    ],
    dependentColumnNames: ["Stock"]
});

The [Filtration] business rule (Terrasoft.RuleTypes.Filtration)

This business rule can be used for filtration of lookup columns by condition, or by another column value. Values of the config configuration object that are used:

  • ruleType – should contain the Terrasoft.RuleTypes.Filtration value for this rule.
  • triggeredByColumns – the column array that triggers the rule.
  • events – an event array, defining the time of running business rules. It should contain values included into the Terrasoft.BusinessRuleEvents enumeration.
  • Filters – filter. The property should contain the Terrasoft.Filter class instance.
  • filteredColumn – the column used for filtering values.

Use cases

Case of filtering per condition

When selecting a value in the [Product] lookup column, only the products containing the true value in the [Active] column of the [Product in invoice] detail are available.

Terrasoft.sdk.Model.addBusinessRule("InvoiceProduct", {
    ruleType: Terrasoft.RuleTypes.Filtration,
    events: [Terrasoft.BusinessRuleEvents.Load],
    triggeredByColumns: ["Product"],
    filters: Ext.create("Terrasoft.Filter", {
        modelName: "Product",
        property: "Active",
        value: true
    })
});

Case of filtering per other column value

The [Contact] field on the record edit page of the [Invoices] section should be filtered based on the [Account] field value.

Terrasoft.sdk.Model.addBusinessRule("Invoice", {
    ruleType: Terrasoft.RuleTypes.Filtration,
    events: [Terrasoft.BusinessRuleEvents.Load, Terrasoft.BusinessRuleEvents.ValueChanged],
    triggeredByColumns: ["Account"],
    filteredColumn: "Contact",
    filters: Ext.create("Terrasoft.Filter", {
        property: "Account"
    })
});

The [Mutual Filtration] business rule (Terrasoft.RuleTypes.MutualFiltration)

This business rule enables mutual filtering of two lookup fields. Works only with columns with the “one-to-many” relationship, e.g., [Country] – [City]. Create a separate business rule for every field cluster. For example, for the [Country] – [Region] – [City] and the [Country] – [City] clusters, create three business rules:

  • [Country] – [Region];
  • [Region] – [City];
  • [Country] – [City].

Values of the config configuration object that are used:

  • ruleType – should contain the Terrasoft.RuleTypes.MutualFiltration value for this rule.
  • triggeredByColumns – the column array that triggers the rule.
  • Соnnections – object array that configures cluster relationship.

Use cases

Mutual filtration of the [Country], [Region] and [City] fields.

Terrasoft.sdk.Model.addBusinessRule("ContactAddress", {
    ruleType: Terrasoft.RuleTypes.MutualFiltration,
    triggeredByColumns: ["City", "Region", "Country"],
    connections: [
        {
            parent: "Country",
            child: "City"
        },
        {
            parent: "Country",
            child: "Region"
        },
        {
            parent: "Region",
            child: "City"
        }
    ]
});

Mutual filtration of the [Contact], [Account] fields.

Terrasoft.sdk.Model.addBusinessRule("Activity", {
    ruleType: Terrasoft.RuleTypes.MutualFiltration,
    triggeredByColumns: ["Contact", "Account"],
    connections: [
        {
            parent: "Contact",
            child: "Account",
            connectedBy: "PrimaryContact"
        }
    ]
});

The [Regular expression] business rule (Terrasoft.RuleTypes.RegExp)

Verifies the conformity of the column value with the regular expression. Values of the config configuration object that are used:

  • ruleType – should contain the Terrasoft.RuleTypes.RegExp value for this rule.
  • RegExp – regular expression whose conformity with all the triggeredByColumns array columns is verified.
  • triggeredByColumns – the column array that triggers the rule.

Use case

Terrasoft.sdk.Model.addBusinessRule("Contact", {
    ruleType: Terrasoft.RuleTypes.RegExp,
    regExp : /^([0-9\(\)\/\+ \-]*)$/
    triggeredByColumns: ["HomeNumber", "BusinessNumber"]
});
© 2011 - 2019 BPMonline. All rights reserved.

Did you find this information useful?

How can we improve it?