How to redirect default custom module view to another layout?

Hi everyone, I have a custom module and I'm trying to redirect it's default module view (the one that would show a list view) when you click on the module name from the main module menu at the top of the page. The best I can come up with is this:

Add the code below to this file: modules/MyCustomModule/clients/base/layouts/default/default.js

({
  extendsFrom: 'DefaultLayout',
    initialize: function(options) {
        this._super('initialize', [options]);
        window.SUGAR.App.router.navigate('#MyCustomModule/layout/setup', {trigger:true});
    }
})

This works. It will redirect to the layout specified on line 5, however it throws a "Uncaught TypeError: Cannot read property 'append' of null" in sidecar. No matter what I put for line #5 (console.log, alert, another function, etc.) it doesn't matter, it will throw the "Uncaught TypeError". If I remove line #5 there is no error at all.

Is there a way to do this without the javascript error? Is there a better way to redirect from the default module page?

Thanks!

  • Hi Chad,

    I think you are looking for this redirect method.

    app.router.redirect('#MyCustomModule/layout/setup');
    

    However, I would recommend you to change your custom modules record layout to your custom layout/setup.

    Have a look at these two documents, i think it would give better understanding of layouts and views;

    Layouts - Developer Guide

    Overriding Layouts - Developer Guide

    Hope these informations helpful

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Thanks for the reply Tevfik. I understand the routing part.

    The part I'm not sure of is how to change the default behavior of a module. You know when you create a new module and it shows up on the top navigation bar? For example, say I create a new module called CustomModule. When you click on it from the main navigation bar at the top, it will take you to https://my.sugar.com/#CustomModule This view will usually show a recordlist view of records for the module.

    What I want to do is when the customer goes to https://my.sugar.com/#CustomModule  it redirects them to https://my.sugar.com/#CustomModule /layouts/setup

    Does that makes sense? Is that possible?

    My example in the original post does that, but it throws the javascript errors.

  • Hi Chad,

    My approach would be changing the list view layout with your custom layout.

    In order to do that;

    Copy records.php in ./modules/CustomModule/clients/base/layouts/records/records.php to ./custom/modules/CustomModule/clients/base/layouts/records/records.php and make this changes;

    $viewdefs['CustomModule']['base']['layout']['records'] = array(
        'components' => array(
            array(
                'layout' => array(
                    'components' => array(
                        array(
                            'layout' => array(
                                'components' => array(
                                    array(
                                        'view' => 'list-headerpane',
                                    ),
                                    array(
                                        'view' => 'setup', // here is your layout
                                        'primary' => true,
                                    ),
                                ),
                                'type' => 'simple',
                                'name' => 'main-pane',
                                'span' => 8,
                            ),
                        ),
                        .
                        .
                        .
    

    This would make your list view automatically your custom layout.

    Your redirect approach would work as well but no need to increase loading time.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Perfect! That's exactly what I needed.

    No sense to redirect when you have the tools to just throw my own view in the layout. Didn't think of that.

    Thanks!