Validating Multiple Asynchronous Results in Creatio

In a previous article I showed how to asynchronously validate a result when saving a page in Creatio. This is needed when validating something when a page is saved and the validation requires an asynchronous function, such as an EntitySchemaQuery. At the end of that article, I mentioned how you would go about doing this for validating multiple asynchronous results at the same time by using Terrasoft.chain to chain all the asynchronous validation function together. In this article I will describe how to do this in detail.

Refer to the original article forĀ Asynchronous Validation on Pages in Creatio

In order to do this, it is easiest if you split up each asynchronous validation into it’s own function. This function would look like this:

validateThing1: function(callback, scope) {
    var result = {
        success: true,
        message: ""
    };
 
    // do whatever async call to validate and then call below to return the result, 
    // setting result.success = true if validation passed or result.success = false 
    // if failed. If the validation failed, also set the message (will be displayed to user)

    callback.call(scope || this, result);
}

Then, in the asyncValidate function itself, you’ll use Terrasoft.chain to chain all the validation function together. In this scenario, I have two validation functions, structured like the sample above, that are named validateThing1 and validateThing2.

asyncValidate: function(callback, scope) {
    this.callParent([function(response) {
        if (!this.validateResponse(response)) {
            return;
        }
        Terrasoft.chain(
            function(next) {
                this.validateThing1(function(response) {
                    if (this.validateResponse(response)) {
                        next();
                    }
                }, this);
            },
            function(next) {
                this.validateThing2(function(response) {
                    if (this.validateResponse(response)) {
                        next();
                    }
                }, this);
            },
            function(next) {
                callback.call(scope, response);
                next();
        }, this);
    }, this]);
}

Now, when the page is saved, each validation function will be chained, each executing the next, before the final result is obtained to determine if the validation was successful or not.

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.

1 Comment

  1. This is great. Thank you.

    Reply

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!