Skip to main content
Version: 10

Virtual objects basics

Level: advanced
note

This functionality is available for Creatio 10.2 and later.

Business data is often stored outside Creatio, for example, orders in an enterprise resource planning (ERP) system or client documents in a bank system. Copying such data to Creatio requires synchronization, and the copy can become outdated or break the rules that forbid storing the data in Creatio. A virtual object enables users to view and change such records on Creatio pages and in business processes while the records stay in the data source. Creatio does not store the records of a virtual object. Your code reads the records from the data source and saves the changes there.

Virtual object use cases​

Use a virtual object when the data must stay in the data source, must always be current, or must not be copied to Creatio. For example:

  • Show records that another external system stores, for example, orders, invoices, or transactions, without copying them to Creatio.
  • Show documents that must not be stored in Creatio, for example, client documents in a bank, and let users open them from a page.
  • Show Creatio data in a different shape, for example, records that your code combines from several objects or totals that your code calculates.
  • Show a fixed set of values, for example, a list that your code builds, on Creatio pages.
  • Let users change such records on a Creatio page and save the changes in the data source.

A virtual object reads the data source on every request. Every list, search, and record that a user opens calls your code, and your code calls the data source. Import or synchronize the data into a regular object instead in the following cases:

  • The data source is slow or is not always available.
  • Users need filtering and sorting, which your code has to implement for a virtual object.
  • The data must take part in SQL queries together with other Creatio objects.

Difference between virtual and regular objects​

A virtual object works in Creatio the same way as a regular object. A virtual object differs from a regular object in where Creatio stores the records and how Creatio reads them. The following table lists the object types and their data storage.

Object type

Record storage

Record reading

Regular object

A table in the Creatio database.

SQL queries.

Regular object with the Represents Structure of Database View checkbox selected in the Object Designer

A view in the Creatio database.

SQL queries.

Virtual object with the Virtual checkbox selected in the Object Designer

Any data source that your code reaches, for example, an external system, Creatio data that your code combines or calculates, or a fixed set of values.

Your code. The code can also apply its own logic, for example, calculate a value, combine several sources, or reject a change. Creatio does not run SQL queries for a virtual object, so code that builds SQL queries for a virtual object fails.

You create a virtual object in the Object Designer and add columns, a primary key, and a displayed value to it in the same way as for a regular object. Creatio does not apply access permissions to the records of a virtual object. Implement the access checks that your data requires in the query executor and the event listener.

In upcoming releases, Creatio checks the following permissions for all virtual objects, even if the query executor and the event listener do not implement these checks:

  • Operation permissions that define which users can add, read, change, and delete records of the object.
  • Column permissions that define which users can read and change each column of the object.

If users or user roles do not have the required permissions, they see empty lists or fields or cannot save records. Make sure that all users and user roles that work with virtual objects, including portal users, have the required permissions. To find the virtual objects whose permissions you need to review:

  • For Creatio on-site, run the script for Microsoft SQL Server or PostgreSQL. The script finds custom virtual objects, base virtual objects that include custom columns, and base virtual objects whose permissions were changed. The script lists base and custom objects separately.
  • For Creatio in the cloud, Creatio support contacts you if the automated check finds objects whose permissions you need to review.

Virtual object structure​

Since a virtual object has no database table, Creatio passes every operation to the code that you write for the object. The following table lists the structural items of a virtual object.

Structural item

Purpose

Object that has the Virtual checkbox selected in the Object Designer

Defines the columns that Creatio shows. Creatio does not create a database table for the object.

Query executor

C# class that returns records when Creatio reads the object.

Event listener

C# class that saves the changes in the data source when a user adds, changes, or deletes a record. A read-only virtual object does not need an event listener.

After you implement the query executor and the event listener, compile the configuration. If Creatio runs on .NET, restart Creatio, since Creatio registers the query executor and the event listener only when Creatio starts. Creatio on .NET Framework restarts after the compilation automatically.

Example: Manage orders stored in an external system.

Query executor​

Creatio reads a virtual object as follows:

  1. A page, a list, a business process, or your code builds an EntitySchemaQuery query to the virtual object.
  2. Creatio finds the query executor of the object by the name that consists of the object code and the QueryExecutor suffix, for example, UsrExtOrderQueryExecutor.
  3. Creatio calls the GetEntityCollection() method of the query executor.
  4. The query executor reads the data and returns a collection of object records.

The query executor receives the whole query: the columns, filters, sort order, number of records to return (RowCount), and number of records to skip (SkipRowCount). Creatio does not filter or sort the records that the query executor returns and does not split the records into batches. Users see exactly these records. If the query executor ignores a filter, users see records that do not match the filter. You decide which parts of the query the query executor supports.

The following table lists the queries that a Freedom UI app sends.

User action

Query content

Open a list

No filter. The sort column and the batch size.

Search in a list

A group of filters joined by the OR operator. Text columns use the Contain or StartWith comparison type, depending on the "String columns filter" (StringColumnSearchComparisonType code) system setting. Out of the box, the value is set to "1," and the list search uses the Contain comparison type. If the value is set to "0," the list search uses the StartWith comparison type. If the search text is a number, number columns use the Equal comparison type.

Open a record

The Id = {Record ID} filter.

Select all records in a list or view totals using the Summaries button

A count or another aggregation column. The RowCount property is "-1."

Learn more about other queries: Use virtual objects in Creatio tools.

Before saving or deleting a record, Creatio also reads the record by ID using the query executor. Creatio marks the records that the query executor returns as existing records, so a save after a read changes the existing record.

To implement a query executor, follow the instructions: Implement a query executor.

Event listener​

When a user saves or deletes a record of a virtual object, Creatio raises the regular entity events but writes nothing to the database. The event listener writes the changes to the data source. The following table lists the events that Creatio raises for each operation.

Operation

Events

Event that writes the changes to the data source

Add a record

OnSaving → OnInserting → OnInserted → OnSaved

OnInserting

Change a record

OnSaving → OnUpdating → OnUpdated → OnSaved

OnUpdating

Delete a record

OnDeleting → OnDeleted

OnDeleting

An event listener that you register for the object using the [EntityEventListener(SchemaName = "{Object code}")] attribute receives all events listed in the table. If the event listener has no method for an operation, for example, the OnUpdating() method, Creatio reports that the record is saved, but the data source does not change. A global event listener (an event listener registered for all objects) receives only the OnSaving, OnSaved, OnDeleting, and OnDeleted events.

To implement an event listener, follow the instructions: Implement an event listener.

Virtual objects in Creatio tools​

Freedom UI list and form pages use a virtual object as a data source, and users search, open, change, add, and delete its records in the same way as records of a regular object. You can work with a virtual object in the following Creatio tools:

  • Application Hub. Create an app that includes a list page and a form page for a virtual object using the Link to an existing object checkbox in the Advanced parameters block of the New application window.
  • Freedom UI Designer. Show the records of a virtual object in a list or in another component that has the Object parameter in the setup area.
  • Dashboard Designer. Show the totals and records of a virtual object in a widget that has the Object parameter in the setup area, for example, a metric or a pivot table.
  • Freedom UI Mobile Designer. Show the records of a virtual object in Creatio Mobile using the List component that has the Object parameter in the setup area.
  • Process Designer. Read, add, change, and delete the records of a virtual object using the Read data, Add data, Modify data, and Delete data process elements.

When you select a virtual object, the tool shows a warning. The warning reminds you that the object supports only the operations that its code implements. Learn more: Use virtual objects in Creatio tools.


See also​

Manage orders stored in an external system

Use virtual objects in Creatio tools

Implement a virtual object