Deleting a Record from Client-Side Code using the Model Class in a Creatio Freedom UI Page

In classic Creatio pages, to delete a new record you would use a DeleteQuery. Now, in Freedom UI pages you can delete 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 an array of filters for the record (or records) we want to delete. In this sample, we’ll be deleting a single account, so we’ll first create an account model, then pass the details of the account to delete to the Model’s delete function. Let’s look at the code to delete an account:

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

// delete the new account
const result = await accountModel.delete([{
    type: sdk.ModelParameterType.PrimaryColumnValue,
    value: someAccountId
}]);

The result returned by the insert provides an object with the following properties:

  1. success: true/false
  2. rowsAffected: Number of rows affected by the operation, in this case, 1
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!