Skip to main content
Version: 10

Object-level business rules in DataService and OData 4 requests

Level: advanced
note

This functionality is available for Creatio 10.2 and later.

Object-level business rules keep data consistent: they populate values, make fields required or read-only, and filter lookups. Previously, Creatio applied object-level business rules only on Freedom UI pages, so an integration could save data that breaks these rules. Since version 10.2, Creatio enforces object-level business rules on the server when an integration saves data through DataService or OData 4. Creatio runs enforcement of object-level business rules inside the record save. If the save breaks a rule, Creatio rejects the whole save, writes no data, and returns the list of broken rules. The server uses the same object-level business rules that Freedom UI pages apply, so you do not need to create separate rules for integrations. Page-level business rules still run only on Freedom UI pages.

Out of the box, Creatio enforces object-level business rules for the following users:

  • The "Creatio.ai Studio" technical user. Creatio AI Studio agents and AI Twin work through this user. Enforcement of object-level business rules is enabled both in new Creatio and in Creatio updated to version 10.2.
  • Every new technical user. For example, a technical user of a new OAuth integration for coding agents such as Claude Code and Codex, a customer's AI agent, or a data sync. Creatio enables enforcement of object-level business rules when it creates the user, whether you add the user together with an OAuth integration, in the Users and Technical users sections of the System Designer, or through the API.

Technical users that existed before Creatio was updated to version 10.2 keep enforcement of object-level business rules disabled. Their integrations work as before.

Additional features that manage object-level business rule enforcement​

The following table lists the additional features that manage object-level business rule enforcement.

Additional feature

Description

EnableObjectBusinessRulesOnSave

Manages the enforcement of object-level business rules for all users. Out of the box, the additional feature is enabled. If the additional feature is disabled, no save runs the rules regardless of the other additional features. Creatio keeps the per-user states and applies them again when you enable the additional feature.

EnforceObjectBusinessRulesPerUserOnDataService

Enforces the rules on DataService saves of the user. Out of the box, the additional feature is enabled for new technical users. To change the state, use one of the following tools:

EnforceObjectBusinessRulesPerUserOnOData

Enforces the rules on OData 4 saves of the user. Out of the box, the additional feature is enabled for new technical users. To change the state, use one of the following tools:

The Enforce object business rules checkbox on the technical user page enables or disables both the EnforceObjectBusinessRulesPerUserOnDataService and EnforceObjectBusinessRulesPerUserOnOData additional features at once. In the Feature toggling section, you can change these additional features independently. This enables an administrator to exempt an integration on one data service and keep enforcement of object-level business rules enabled on the other data service. A change applies from the next save of the user on every Creatio application server, without a restart.

Conditions for enforcing object-level business rules​

To decide whether to enforce the rules for a save, Creatio performs the following actions:

  1. Check the EnableObjectBusinessRulesOnSave additional feature. If the additional feature is disabled, no rules run.

  2. Check the data service of the save. If the save does not come through DataService or OData 4, no rules run.

  3. Identify the user whose additional feature state applies. If an integration uses the authorization code grant and the Integration user field on the OAuth integration page is filled out, this is the integration user. Access rights and the "Created by" column value still belong to the user who logged in. This is how Creatio AI Studio and AI Twin enforce the rules for every user who works with them. Learn more: Authorize external requests using authorization code grant. Otherwise, this is the user who saves the data. For an integration that uses the authorization code grant without an integration user, this is the user who logged in. Out of the box, enforcement of object-level business rules is disabled for regular users.

  4. Read the additional feature of the data service for that user:

    1. The user's own state. The user's own state always takes priority over a user role. If the additional feature is disabled for a user in the Feature toggling section, enforcement of object-level business rules stays disabled for this user even if the additional feature is enabled for the user's user role.
    2. The state of the user roles. An additional feature that is enabled for a user role applies to every user of the user role that has no state of their own.
    3. The out-of-the-box state, i.e., disabled.
  5. Enforce the rules if the additional feature is enabled. If the additional feature is disabled, the save works as before.

Operations that run object-level business rules​

The operations that Creatio checks when applying object-level business rules depend on the data service that the integration uses.

If the integration uses DataService, Creatio checks the following queries:

  • InsertQuery.
  • UpdateQuery, including a query that inserts a record because no matching record exists.
  • UpdateLocalizationQuery.
  • InsertQuery, UpdateQuery, and UpdateLocalizationQuery inside BatchQuery.

If an operation inside a BatchQuery query breaks a rule and the ContinueIfError property of the BatchQuery query is set to "true," Creatio rejects only that operation and runs the other operations. The response includes the HasErrors property set to "true." If the ContinueIfError property is set to "false," Creatio rolls back the whole BatchQuery query. To save the operations that break no rules, set the ContinueIfError property to "true."

If the integration uses OData 4, Creatio checks the following requests:

  • Create a record.
  • Update a record.
  • Write or delete the value of a stream column, i.e., PUT and DELETE requests to the {Entity set}({Record ID})/{Column} path.

If a request inside a changeset of an OData 4 $batch request breaks a rule, Creatio rejects only that request and does not roll back the changeset. The requests of the changeset that ran before the failed request stay saved. The requests that follow the failed request run only if the $batch request has the Prefer: odata.continue-on-error header.

Creatio does not check the following saves. These saves work as before:

  • Saves that users make on pages and in Creatio Mobile.
  • Saves from business processes.
  • Excel import.
  • Saves through OData 3.
  • Saves from custom code.
  • Records that Creatio saves as a side effect of another save.

Handling of object-level business rule actions​

The following table lists how Creatio handles object-level business rule actions when an integration saves data.

Business rule action

Behavior on save

Make elements editable

Creatio does not reject the save. The action cancels the read-only state that another business rule sets for the same field. If several business rules set the state of the same field, the last active business rule applies.

Make elements read-only

Creatio rejects the save in the following cases:

  • The integration creates a record and passes a value to the field.
  • The integration updates a record and changes the field value. If the integration passes the current field value, Creatio saves the record.

Make elements required

Creatio rejects the save if the field is empty after the save. This includes updates that do not pass the field if the field is already empty in the record.

Make elements optional

Creatio does not reject the save. The action cancels the required state that another business rule sets for the same field. If several business rules set the state of the same field, the last active business rule applies.

Set values

Creatio handles the value in the following way:

  • Populates the value if the integration does not pass it.
  • Does not overwrite a value that the integration passes.
  • Considers the value not passed if the passed value equals the column default.

Apply filter

Creatio rejects the save if the value does not match the filter.

Apply static filter

Creatio rejects the save if the value does not match the filter.

Error handling for business rule violations​

If Creatio rejects a save, the error format remains the same. Creatio returns the 500 Internal Server Error HTTP status code. The location of the error text depends on the data service:

  • For DataService, Creatio returns the error text in the responseStatus.Message property, sets the success property to "false," and sets the responseStatus.ErrorCode property to "ObjectBusinessRuleViolationException." The error code distinguishes a business rule violation from other errors. For a BatchQuery query with the ContinueIfError property set to "true," every failed operation has its own ErrorCode and Message properties.
  • For OData 4, Creatio returns the error text in the error.innererror.message property.

The following template shows the response to a DataService InsertQuery or UpdateQuery query that breaks a rule.

DataService query response
{
"responseStatus": {
"ErrorCode": "ObjectBusinessRuleViolationException",
"Message": "{Error text}",
"Errors": []
},
"rowsAffected": -1,
"nextPrcElReady": false,
"success": false
}

The following template shows the response to a DataService BatchQuery query whose ContinueIfError property is set to "true" and whose second query breaks a rule. Creatio returns the 200 OK HTTP status code.

DataService BatchQuery response
{
"queryResults": [
{
"rowsAffected": 1,
"nextPrcElReady": false,
"success": true
},
{
"responseStatus": {
"ErrorCode": "ObjectBusinessRuleViolationException",
"Message": "{Error text}",
"Errors": []
},
"rowsAffected": -1,
"nextPrcElReady": false,
"success": false
}
],
"hasErrors": true
}

The following template shows the response to an OData 4 request that breaks a rule.

OData 4 response
{
"error": {
"code": "",
"message": "An error has occurred.",
"innererror": {
"message": "{Error text}",
"type": "",
"stacktrace": ""
}
}
}

The following example shows the error text for a save that breaks 2 rules.

UsrObrTest: 2 business rules violated.
readOnly Name (Name): Name cannot be changed. Rule 'OBR test rule'
required Description (Description): Description is required. Rule 'OBR test rule'

The first line of the error text names the object and the number of broken rules. Every next line describes one broken rule: the type of violation, the field, the message, and the rule name. Use the rule name to find the rule in the Object Designer. The type of violation is one of the following values: required, readOnly, lookupFilter, staticFilter, cascadeLimit, evaluationFailure.

Enforcement setup for integrations​

After Creatio is updated to version 10.2, technical users of existing integrations keep enforcement of object-level business rules disabled. Creatio lets you enable enforcement of object-level business rules in the following ways:

  • For an existing integration
    1. Make sure the integration has its own technical user.

    2. Select the Enforce object business rules checkbox on the technical user page in a pre-production environment. Instructions: Enforce object-level business rules for a technical user (user documentation).

    3. Run the integration.

    4. Fix the data or the business rules for every rejected save.

    5. Select the Enforce object business rules checkbox on the technical user page in the production environment.

      If the integration starts failing in the production environment, clear the checkbox for its technical user only.

    As a result, Creatio enforces object-level business rules on the data that the integration saves through DataService or OData 4 and rejects every save that breaks a rule.

  • For many integrations at once
    1. Add the technical users of the integrations to a single user role.
    2. Enable the EnforceObjectBusinessRulesPerUserOnDataService and EnforceObjectBusinessRulesPerUserOnOData additional features for that user role in the Feature toggling section.

    As a result, Creatio enforces object-level business rules for every technical user of the user role that has no state of their own.

The following table lists how to disable enforcement of object-level business rules.

Case

Solution

Creatio rejects the saves of an integration.

Clear the Enforce object business rules checkbox on its technical user page.

Creatio rejects the saves of an integration on one data service only.

Disable the additional feature of that data service for its technical user in the Feature toggling section.

Enforcement of object-level business rules must be disabled for all users.

Disable the EnableObjectBusinessRulesOnSave additional feature in the Feature toggling section.


See also​

Manage technical users (user documentation)

Authorize external requests using authorization code grant