Validating That a User Entered Value is Unique in Creatio (formerly bpm’online)

There might be times where a value entered by a user needs to be unique. For example account numbers, each account will have it’s own unique number. To do this you will need to do a query to make sure no other account has the same account number.

Let’s take a look how to set up this example. First you will need to create your account number field and then set up a change event in your code. You can see how to wire up this change event here. The actual code to go in the change event would look like this.

var code = this.get("UsrAccountNumber");

if (code === "") {
var esq = Ext.create("Terrasoft.EntitySchemaQuery", { 
	rootSchemaName: "Account" 


var filterCode = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UsrAccountNumber", code);
var filterId = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.NOT_EQUAL, "Id", this.get("Id"));

esq.getEntityCollection(function(result) {
	if (result.success) {
		var entities =  result.collection.getItems();
		if (entities.length > 0) {
			var acc = entities[0];
			var name = acc.values.Name;
			Terrasoft.showErrorMessage("Sorry, the account " + name + " already has the code " + code);
			this.set("UsrAccountNumber", "");
}, this);

What that code does is it first gets the number entered by the user and then sets up a EntitySchemaQuery to query the accounts. I’m adding two filters to the EntitySchemaQuery. The first one is finding all accounts that have the same account number, but the second filter is telling the query to not get the one I’m currently on. Then it does the query and checks the results. If the number of records returned in the result is not equal to zero then I know that another account has the same number so I clear the field and let the user know by displaying a error message. It’s a pretty easy way to make sure the value is unique and it can be used for other scenarios as well.

Want content like this delivered to your inbox? Sign up for our newsletter!

1 Comment

  1. That is helpful and can be put into use now


Submit a Comment

Your email address will not be published. Required fields are marked *