Redirect to a record view  in php-logichook

Hi All,

                How can we redirect to the record view of another record(sidecar) using the after save logichook(php)

Regards André Lopes Francesca Shiekh hats

Sidhu

  • Hi All,

                    I have tried this in my after save logichook.

     $script = navigateToSidecar(
                    buildSidecarRoute("Calls","0ef6a492-72ae-11e7-819d-fa163e8c8e90", translateToSidecarAction("edit"))
                );
    _ppl("<script>$script</script>");
    echo "<script>$script</script>"

    But i am getting an error.

    What can be the solution for this

    Tevfik Tümer 

    i am getting this when i log  in the above code but i am unable to redirect in after save logichook.

     <script>parent.SUGAR.App.router.navigate('Calls/0ef6a492-72ae-11e7-819d-fa163e8c8e90/edit', {trigger: true});</script>

    Regards

    Sidhu

  • Hi All,

                   Any suggestions?

    Regards

    Sidhu

  • Hi sidhu sidhu 

    I would suggest you to manage the redirect at view controller instead.

    You can extends the clients/base/views/record/record.js and override the method _saveModel. This way you can listen to this.model.save({}, options); and redirect it accordingly.

    Kind regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • I do agree with the answer from André Lopes.

    Logic hooks on the standard MVC are considered a model component, therefore interacting with the backend logic of the system, so should be independent from what happens to the UI.

    Cheers

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Hi André Lopes

                       This is what i have tried but i am unable to redirect in the success call back.

    How can i override save button call? 

    Regards

    Sidhu

  • Hi,

                 I have tried in the record.js in the saveModel function

       _saveModel: function() {
            var options,
                successCallback = _.bind(function() {
                        
                        alert("successcallback");
                        var test="";
                        //console.log(JSON.stringify(this.model));
                        JSON.stringify(this.model,function(key,value){
                             
                             console.log("key "+key);
                             console.log("value "+value);
                             console.log("value "+value.new_call_id_c);
                             test=value.new_call_id_c;
                             console.log("test "+test);
                             });
                    // Loop through the visible subpanels and have them sync. This is to update any related
                    // fields to the record that may have been changed on the server on save.
                    _.each(this.context.children, function(child) {
                        if (child.get('isSubpanel') && !child.get('hidden')) {
                            child.get('collapsed') ? child.resetLoadFlag(false) : child.reloadData({recursive: false});
                            console.log("test if "+test);
                        }
                        console.log("test if "+test);
                    });
                   
                    App.router.navigate(test, {trigger: true});//this is asking confirmation
            
                    if (this.createMode) {
                        app.navigate(this.context, this.model);
                        console.log("if createMode");
                    } else if (!this.disposed && !app.acl.hasAccessToModel('edit', this.model)) {
                        //re-render the view if the user does not have edit access after save.
                        this.render();
                        console.log("else createMode");
                    }
                }, this);

            //Call editable to turn off key and mouse events before fields are disposed (SP-1873)
            this.turnOffEvents(this.fields);

            options = {
                showAlerts: true,
                success: successCallback,
                error: _.bind(function(error) {
                    if (error.status === 412 && !error.request.metadataRetry) {
                        this.handleMetadataSyncError(error);
                    } else if (error.status === 409) {
                        app.utils.resolve409Conflict(error, this.model, _.bind(function(model, isDatabaseData) {
                            if (model) {
                                if (isDatabaseData) {
                                    successCallback();
                                } else {
                                    this._saveModel();
                                }
                            }
                        }, this));
                    } else if (error.status === 403 || error.status === 404) {
                        this.alerts.showNoAccessError.call(this);
                    } else {
                        this.editClicked();
                    }
                }, this),
                lastModified: this.model.get('date_modified'),
                viewed: true
            };

            options = _.extend({}, options, this.getCustomSaveOptions(options));

            this.model.save({}, options);
        },

    You can see the code at line number 26.

    It is asking confirmation like - "There are some unsaved changes do you want to continue" i dont want this confirmation while i am navigatign.

    Can you please update what is the best i can do to prevent this confirmation and redirect to the new record.

    I am storing the new record value in a field called new_call_id_c via a logichook and in the save model function i am using it to redirect.

    Regards

    Sidhu

  • You need to override the method 'hasUnsavedChanges' and make it returns false on specific conditions (when it should redirect to some other record view).

    Cheers

    André Lopes
    Lampada Global
    Skype: andre.lampada