Inserting a Record from Client-Side Code using InsertQuery in Creatio (formerly bpm’online)

There might be times when you need to insert a record from client-side code on a page in Creatio. While it is easy to add records in a process, you can also do the same from the form code itself using an InsertQuery object. Let’s take a look.

For this scenario, we’ll say we have an object named UsrWidget that’s related to Account. From the account page, we’ll programmatically create a new widget record and relate it to the account. The code for using InsertQuery will look a lot like an EntitySchemaQuery. We’ll create the object and specify the rootSchemaName we’re inserting into and then set the column values to include. Finally, we’ll execute the insert, which also allows for us to specify a callback to happen after the insert is complete (so we could do something like refresh a detail we’ve inserted into, for example). The code would look something like this:

var insert = Ext.create("Terrasoft.InsertQuery", { rootSchemaName: "UsrWidget" });
insert.setParameterValue("UsrAccount", this.get("Id"), Terrasoft.DataValueType.GUID);
insert.setParameterValue("UsrQuantity", 1, Terrasoft.DataValueType.INTEGER);
insert.setParameterValue("UsrPrice", 200.00, Terrasoft.DataValueType.FLOAT);
insert.setParameterValue("UsrInclude", true, Terrasoft.DataValueType.BOOLEAN);
insert.setParameterValue("UsrSerialNumber", "123456", Terrasoft.DataValueType.TEXT);
insert.execute();

The first line simply creates the InsertQuery object and specifies the type of entity object we’re inserting. Then we set each column value, which we also have to specify what the type is for that column value using Terrasoft.DataValueType. How do we know the available types for Terrasoft.DataValueType? You can see all of the possible values in the documentation, or you can open up your browser’s DevTools on a Creatio page (any page) and type “Terrasoft.DataValueType” in the console and hit enter and you’ll see the list of available types.

Lastly, we execute the insert. In the code above, we’re just executing it, however we can also provide a callback function to execute after the insert is complete. Like this:

insert.execute(function() {
    // do something here
}, this);

or this:

insert.execute(this.myCallbackFunction, this);

In the following two articles, I will cover doing the same with updates and deletes.

As always, you should always consider where the best place is to perform an operation like this. Keep in mind, doing this from the page code means that the logic won’t happen for imports or things that might trigger from other server events since it only exists on the page.

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!