Show Fields of Any Module in a Custom View

Okay, so this is a pretty advanced level question (I think) and only people who have really worked in depth with SugarCRM might be able to answer this. 

What I am trying to achieve is this.

I want to load and render all (or selected) fields of any module (Dynamic), for e.g. "Tasks" Module, into the record view of another custom module e.g. "Custom_Templates" Module. I want to be able to edit the values in those fields as well. What I am looking to do is append those fields below the current fields that I have in my "Custom_Templates" Module.

So, here is what I have done so far.

  • I have created a new custom Layout.  (modules/Custom_Templates/clients/base/layouts/related-module-fields-layout)
  • I have created a new custom View. (modules/Custom_Templates/clients/base/views/related-module-fields-view)
  • I have added the new custom layout and view into the record layout of my "Custom_Templates" Module.
$module_name = 'Custom_Templates';
$viewdefs[$module_name]['base']['layout']['record'] = array(
    'components' => array(
        array(
            'layout' => array(
                'type' => 'default',
                'name' => 'sidebar',
                'components' => array(
                    array(
                        'layout' => array(
                            'type' => 'base',
                            'name' => 'main-pane',
                            'css_class' => 'main-pane span8',
                            'components' => array(
                                array(
                                    'view' => 'record',
                                    'primary' => true,
                                ),
                                array(
                                    'layout' => 'related-module-fields-layout',
                                ),
                                array(
                                    'layout' => 'extra-info',
                                ),

In my related-module-fields-view.hbs file, I have added 

<h1 id='new-id'>I AM HERE!</h1>

And I can see this heading appended in the record view at the bottom. But this is as far as I have gone. I am stuck here. I can't figure out how I can populate fields of any module from it's metadata and render those fields in this view. Any help in this regard would be appreciated.

  • I suppose, somehow, you will choose which module and which record to pull data from, right?

    We have done something similar for a customer, but instead pulling data from a module/record we pull data from a metadata outside SugarCRM instance and injected all the fields/values into view the way user would be able to fill in empty fields/ fix wrong values and then send back to the integrated application.

    Basically you need a endpoints which will fetch the record view for a given module and its populated bean as well. Find code below for method initialize in the js view:

    initialize: function (options) {
    this._super('initialize', [options]);

    var document_id = options.context.get('documents_tl_rightsignature_1documents_ida'),
    parent_type = options.context.get('parent_type'),
    parent_id = options.context.get('parent_id'),
    url = 'Documents/templateDetails/' + document_id + '/' + parent_type + '/' + parent_id,
    self = this;

    App.api.call('GET', App.api.buildURL(url),
    {}, {
    success: function(data) {
    if(data.status == 'success') {
    self.meta = data.viewdefs;
    self._render();
    self.model.set(data.fields);
    self.editClicked();
    } else {
    app.alert.show('rs-template', {
    level: 'error',
    title: app.lang.get('LBL_TEMPLATE', 'TL_RightSignature') + " : ",
    messages: data.message,
    autoClose: true,
    autoCloseDelay: 5000
    });
    }
    },
    error: function (e) {
    app.alert.show('rs-template', {
    level: 'error',
    title: app.lang.get('LBL_TEMPLATE', 'TL_RightSignature') + " : ",
    messages: e,
    autoClose: true,
    autoCloseDelay: 5000
    });

    console.log("error");
    console.log(e);
    }
    }, {async: true}
    );
    },

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi André,

     

    While your solution does show a lot of promise, however my client's requirements have changed so I will be going in a different direction. So I won't get a chance to test the solution that you have proposed. Thank you for your answer and time though. I really appreciate it.


    Regards,

    Arslan