Querying Data Using Filter Conditions via the Model Class (Equivalent to EnitySchemaQuery) in a Creatio Freedom UI Page

In previous articles I discussed using the Model class for reading a single record, as well as inserting, updating, and deleting data. I have been holding off on writing an article on the topic of using the model class to retrieve data using filter conditions until the filter classes in the SDK were fixed and working, which is finally the case in Creatio 8.1.1.

Note: The filter classes in the SDK are working as of version 8.1.1 – if you’re using a prior version of Creatio, I’ll show a workaround at the end of the article.

In this article I will show how to use the Model class to retrieve a list of records using filter conditions. This is the Freedom UI equivalent to performing an EntitySchemaQuery. The Model class is available via the new Creatio DevKit SDK.

To use the devkit, you’ll need to add “@creatio-devkit/common” to the modules list of your page. This will look like this (note the “@creatio-devkit/common” in the square brackets and the sdk without quotes in the parenthesis):

define("UsrMyCustomEntity_FormPage", /**SCHEMA_DEPS*/["@creatio-devkit/common"] /**SCHEMA_DEPS*/, 
function/**SCHEMA_ARGS*/(sdk)/**SCHEMA_ARGS*/ {
	return {
		// ... the rest of the page here

Now, with that module available, you can access things in the SDK, such as the Model class. We’ll use this model class to create a model for a specific entity. Then, we’ll define some filter conditions and load the list of records for the conditions. We’ll start with a simple example of loading all Accounts where the Type column has the value of “Partner”. Let’s look at the code:

const accountModel = await sdk.Model.create("Account");

// define filter for Type = Partner
const filters = new sdk.FilterGroup();
await filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Type.Name", "Partner");

// now load the records and provide the filters				
const partners = await accountModel.load({
	attributes: ["Id", "Name", "Type"],
	parameters: [{
		type: sdk.ModelParameterType.Filter,
		value: filters


The end result is we’ll see a list of Accounts who have the Type of Partner output to the console. Well, not the entire record, just the columns we’re asking for in the attributes array. Obviously, the magic here is in the filters. Those should look somewhat familiar since they are very similar to how EntitySchemaQuery filters look.

Workaround for Creatio versions prior to 8.1.1

I mentioned previously, this only works in 8.1.1 and later. Why? The filter classes in the SDK were broken in prior versions. However, you can use a workaround if you’re not on 8.1.1 or later. The workaround is to shallow copy the filter object and then reassign the filter items. That would look like this:

// first, create the filter normally
const customerFilters = new sdk.FilterGroup();
await customerFilters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Type.Name", "Customer");

// now, shallow copy to new object and reassign items
const newCustomerFilters = Object.assign({}, customerFilters);
newCustomerFilters.items = customerFilters.items;

// the newCustomerFilters is the one you'd now use in the model.load

Obviously, that is only necessary if you’re on a version prior to 8.1.1.

Want content like this delivered to your inbox? Sign up for our newsletter!

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

Submit a Comment

Your email address will not be published. Required fields are marked *