
In classic Creatio pages, to insert a new record you would use an InsertQuery. Now, in Freedom UI pages you can insert records using the Model class that is a part of the 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 pass a payload of the record to create. In this sample, we’ll be creating an account, so we’ll first create an account model, then pass the payload of the record to create to the Model’s insert function. The payload is simply an object containing the Column’s an values for the record you’re creating. It can contain any fields you’d like, however, if you don’t include fields that are required the insert will fail. Let’s look at the code to insert an account:
// create account model const accountModel = await sdk.Model.create("Account"); // insert a new account const result = await accountModel.insert({ Name: "New account", Phone: "800-555-1212", Web: "www.someaccount.com" });
The result returned by the insert provides an object with the following properties:
- success: true/false
- rowsAffected: Number of rows affected by the operation, in this case, 1
- primaryAttributes: An array of column/value pairs. For the insert above, the array contains a single element, which is:
{ Id: "81167933-a9b4-42c2-b589-4e9e55bf7b45" }
This will provide you with the Id of the created account. This is a welcomed change for sure – quite a bit easier than using the InsertQuery.
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!