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

In my previous article, I covered how to insert a record from client-side code using InsertQuery. In this article we’ll cover how to update data from client-side code using the UpdateQuery object.

The UpdateQuery looks pretty much the same as the code for the InsertQuery, we’ll create the object and specify the rootSchemaName (the object we’re updating), add the column values we’re updating and execute. However, for an update, we’ll also need to provide a filter (just like with EntitySchemaQuery) that indicates the record, or records, to update. Note, an UpdateQuery can update a single record, or multiple all at once, this all depends on the filters you provide to the UpdateQuery. In this example, we’ll assume we have an object named UsrWidget, that is related to Account, we’re going to set the quantity of all items on the account as the value 10. Let’s look at the code:

var update = Ext.create("Terrasoft.UpdateQuery", { rootSchemaName: "UsrWidget" });
update.filters.add("AccountFilter", 
  update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrAccount", this.get("Id"))
);
update.setParameterValue("UsrQuantity", 10, Terrasoft.DataValueType.INTEGER);
update.execute();

Note, we just create the UpdateQuery, add the filter (in this case, all Widget’s related to the current account), then set the columns we want to update (in this case, just setting the quantity of all records to 10), then we execute. When we add the columns to update, we need to indicate the data type of the column value. As I mentioned in the article about InsertQuery, 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.

Just as with InsertQuery, when we execute the update we can add a callback to occur after the update is complete, like this:

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

or this:

update.execute(this.myCallbackFunction, this);

Next, we’ll cover how to do client-side 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.

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!