Sugar 7 Contact module record view header add middle name

Hello,

I want to add middle name record view header pane in contact module.

Ramana Raju Santhana Francesca Shiekh Alan Apter

Thanks

Dipesh

Offshore Evolution Pvt Ltd

Parents Reply
  • Hi Francesca Shiekh,

    I have already set file, custom/modules/Contacts/clients/base/fields/fullname/fullname.js

    /*
    *  I only wanted to apply this change to the Contacts modules so I put this file in:
    *  custom/modules/Contacts/clients/base/fields/fullname/
    */

    ({
        extendsFrom: 'FullnameField',

        formatMap: {
            'f': 'first_name',
            'l': 'last_name',
            's': 'salutation',
            'm': 'middle_name_c'
        },

        initialize: function(options) {
            // override the name format for this module
            app.user.setPreference('default_locale_name_format', 's f m l');

            this._super('initialize', [options]);
        },

        format: function() {
            var fullname = this.model.attributes.salutation +' '+ this.model.attributes.first_name +' ';
                fullname += this.model.attributes.middle_name_c +' '+ this.model.attributes.last_name;

            return fullname;
        },
    })

    But main issue is this.model.attributes.middle_name_c is blank.

Children
  • I've not tried this myself but I don't think you need to override the format Name Model function, just pass an extra variable to specify the format you want.

    If you look at the app.utils.formatNameModel function in sidecar/src/utils/utils.js

    You will see that you can pass the format you want to override the user format:

      formatNameModel: function(module, data, format) {
          format = format || app.user.getPreference('default_locale_name_format');

    So I would try redefining your format function:

        format: function() {
            var format = 's f m l';
            return app.utils.formatNameModel(this.model.module, this.model.attributes, format);
        },

    The formatNameModel function should do all the work for you based on the format you are passing.

    See if that works.

    In general, to get the attributes' values I use this.model.get('<attribute name>'):

    this.model.get('middle_name_c');

    And to set them use this.model.set('<attribute name>', '<attribute value>');

    this.model.set('middle_name_c', 'Carols'); 

    HTH

    FrancescaS

     

  • You add custom/modules/Contacts/clients/base/fields/fullname/fullname.js

    ({
    extendsFrom: 'FullnameField',
    formatMap: {
    'f': 'first_name',
    'l': 'last_name',
    's': 'salutation',
    'p': 'preferred_name_c',
    'm': 'middle_name_c'
    },
    initialize: function(options) {
    // override the name format for this module
    app.user.setPreference('default_locale_name_format', 's f p m l');
    this._super('initialize', [options]);
    },
    format: function() {
    var fullname = this.model.attributes.salutation +' '+ this.model.attributes.first_name +' ';
    fullname += (!_.isEmpty(this.model.attributes.preferred_name_c)) ? '"'+ this.model.attributes.preferred_name_c +'" ': ' ';
    fullname += this.model.attributes.middle_name_c +' '+ this.model.attributes.last_name;
    return fullname;
    },
    })
  • hi all,

    really useful information and i was able to add the middle name and 2nd last name in my case as in spain we have 2 last names. everything seems to be working fine. just one bit where i am trying to edit the record within the subpanel or list view using action button next to preview, the columns are not aligned correctly and name field in not expanding with

    additional data points. Same is happening with list view. any suggestions how this could be fixed ?

      Subpanel view name not accommodating middle name

  • Hi All,

    Like you added middle name to list view, add to record view also.

    Now you will not get undefined in record view/blank in edit view.