_addComponentsFromDef Issue loading view

Hi,

we created a custom module that is related to opportunities. When we open the opportunity we have a subpanel to shows the related records. So far so good. But when a user clicks the specified record on the custom module something strange happens. For some reason we do receive the following javascript error: 

components_732f65a3ae4ebba78bd0c391d47ef8d0.js:84815 Uncaught (in promise) TypeError: Cannot read property 'link' of undefined
at child.<anonymous> (components_732f65a3ae4ebba78bd0c391d47ef8d0.js:84815)
at eval (eval at e.exports (addScript.js:9), <anonymous>:5:751)
at eval (eval at e.exports (addScript.js:9), <anonymous>:5:2672)
at Function.h.each.h.forEach (eval at e.exports (addScript.js:9), <anonymous>:5:1934)
at Function.h.filter.h.select (eval at e.exports (addScript.js:9), <anonymous>:5:2649)
at child._pruneHiddenComponents (components_732f65a3ae4ebba78bd0c391d47ef8d0.js:84814)
at child._addComponentsFromDef (components_732f65a3ae4ebba78bd0c391d47ef8d0.js:84835)
at child.initComponents (layout.js:240)
at layout.js:245
at Function.h.each.h.forEach (eval at e.exports (addScript.js:9), <anonymous>:5:1934)

I traced it back to the following javascript part: 

clients/base/layouts/subpanels/subpanels.js:

_pruneHiddenComponents: function(components) {
        var hiddenSubpanels = app.metadata.getHiddenSubpanels();
        var visibleSubpanels = _.filter(components, function(component){
            // for some reason the component does not have a 'context' and therefore the 'link' property can not be found
            var relatedModule = app.data.getRelatedModule(this.module, component.context.link);
            return _.isEmpty(_.find(hiddenSubpanels, function(hiddenPanel){
                if (relatedModule !== false) {
                    //hidden subpanels seem to come back in lower case, so we do a case insenstiive compare of module names
                    return hiddenPanel.toLowerCase() === relatedModule.toLowerCase();
                }
                return true;
            }));
        }, this);
        return visibleSubpanels;
    },

The question is why does this error occure? It seems that the component is a subpanel on that specific module that is not loaded correctly. I can't seem to find the cause of the issue. Did someone encounter similar issues in 10.2? and if so how can we fix it?

  • We had a similar issue, and figured that the reason as - the "context" was empty is because it wasn't defined in the subpanel definition.

    Check where your subpanel for the custom module is defined.

    It could be either in 

    custom/modules/Opportunities/clients/base/layouts/subpanels/subpanels.php

    or

    custom/Extension/modules/Opportunities/Ext/clients/base/layouts/subpanels/opportunities_custom_module.php

    In the definition, there should be a "context" array which should contain a "link" name, if it's not present, please add it - it defines the link name, which is used in the JS.

    <?php

    $viewdefs['Opportunities']['base']['layout']['subpanels']['components'][] = array (
    'layout' => 'subpanel',
    'label' => 'LBL_OPPORTUNITIES_CUSTOM_MODULE_TITLE',
    'context' =>
    array (
    'link' => 'opportunities_custom_module',
    )
    ,
    );