AnsweredAssumed Answered

How can I handle errors thrown by logic hook when doing a mass update?

Question asked by Derick van Niekerk on May 7, 2017
Latest reply on May 8, 2017 by André Lopes

I have some hooks to enforce data integrity. For instance, if I try to save an account where the parent account would make the account an ancestor of itself, I throw an error. 


This works great for when 3rd party systems try to insert records that would break Sugar, but if the error is thrown while trying to do a mass update, I have no idea how to handle it. Mass linking fails and freezes - I can't close the dialogue without reloading the page:


Unclosable dialogue when mass linking fails


When inspecting the network traffic, I get the expected 422 error:


Response: {"error":"invalid_parameter","error_message":"The specified parent account would cause a circular dependency!"}


I have already overridden the mass-link.js controller in which I do a few custom checks before handing over to the default mass linking controller:


    extendsFrom: 'MassLinkView',
    beginMassLink: function(options) {
        var massLink = this.getMassUpdateModel(this.module),
            linkModule = this.context.get('module'),
            baseModule = massLink.baseModule;
        if (linkModule == 'Accounts' && baseModule == 'Accounts' && massLink.models.length > 0) {
            // Some custom stuff
            return this._super('beginMassLink', options);
        return this._super('beginMassLink', options);


Try / catch does not work because 'beginMassLink' is an asynchronous request. Is there some way I can hook into the beginMassLink results to handle the error? Or at least be able to close the modal. beginMassLink does not return anything.


Ideally I would like to display the error message, but I would be happy to just have the modal's close button work.