Add additional field to the Selection List in a Related Field

Dear Sugar Users, 

Within our Cases module, we have a related field to the Contacts, in this case it is used to select the Primary Contact of a Case. 

In the "Select Contact..." box that appears (See below). We can type a name component of the contact and a list of selectable contacts will appear. However, there may be contacts of the same name. We can always click the "Search and Select" option to do a more detailed search, however it would be convenient to be able to extend this control to also show the Account for the contact. 

Does anyone know how this can be done? Or what files I need to check to see if it is extendable?


BTW This is Sugar Ent 12.0.2 On Prem. 

Many thanks for your help. 

  • Hi  ,

    There are various way of achieving this. I will give you a very generic example, I'm hopping that will inspire you for your own solutions. 

    You can do this via generic relate customisations. You would create `custom/clients/base/fields/relate/relate.js` with following content:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    ({
    extendsFrom: "RelateField",
    getSearchFields(){
    // get the fields from super;
    const fields = this._super("getSearchFields");
    if (this.getSearchModule() == "Contacts"){
    // append the contact fields for search results
    fields.push("account_name");
    }
    // return
    return fields;
    },
    /**
    * Searches for related field.
    * @param event
    */
    search: _.debounce(function(query) {
    var term = query.term || '',
    self = this,
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Anytime a contact relation field being used this will application wide adds the account_name to end of the contact names. 

    Hope this helps. Slight smile

    Tevfik Tümer
    Sr. Developer Support Engineer

  • Hi  Wow, fantastic reply, this works as expected and I can see how I can use this to extend other controls. 

    I have noticed that the To field on an Email works differently (See below), Could we use the same process to extend this field to show the Contacts Account name too?

    Thanks again. 

  • Hi  ,

    I'm glad it worked as you expected. To do similar changes in emails reciepients much trickier than contacts field. 
    To field works with collections,To be able to show accounts and contacts the users must have a relationship and modify in the collection before pass to select2 (Dropdown).

    You can review: render function in modules/Emails/clients/base/fields/email-recipients/email-recipients.js 

    Tevfik Tümer
    Sr. Developer Support Engineer