Retrieving a Record via the Model Class (Equivalent to EntitySchemaQuery) in a Creatio Freedom UI Page

In my previous article I introduced the Model class, available in the Creatio DevKit SDK. In this article I will show how to use the Model class to retrieve a record. This is the Freedom UI equivalent to performing an EntitySchemaQuery. In this particular example, we’ll be loading a single record, which would be the same as getEntity in 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 load a record given it’s Id value. Let’s look at the code:

const someAccountId "ddd2c965-cd43-4c9e-8ee1-9783a5571be8";

const accountModel = await sdk.Model.create("Account");
const accounts = await accountModel.load({
	attributes: ["Id", "Name", "Type"],
	parameters: [{
		type: sdk.ModelParameterType.PrimaryColumnValue,
		value: someAccountId
	}]
});
					
const account = accounts[0];
if (account.Type.displayValue === "Partner") {
	console.log(account.Name + " is a Partner");
}

The end result is, we read the Account with the Id value we’ve provided and we get the record back. Well, not the entire record, just the columns we’re asking for in the attributes array. Let’s break down what we’re doing there.

First, we create the model for the account object:

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

Then, we load a specific account’s Id, Name, and Type columns, given the Id for the account we want to load:

const accounts = await accountModel.load({
	attributes: ["Id", "Name", "Type"],
	parameters: [{
		type: sdk.ModelParameterType.PrimaryColumnValue,
		value: someAccountId
	}]
});

From there, we just get the first account in the array (the only one since we’ve just asked for one by its primary column – it’s Id column). Then we can read the properties as needed. I do have to admit, I do like working with this new model class so far. This article just focused on one type of load, to retrieve a single record using its primary column value. in a future article, I’ll show how to retrieve a collection of records using filter conditions.

ABOUT THE AUTHOR

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 *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!