Is it possible to convert a relate field to a multienum?

Currently I have a custom module ('Brands') with a many to many relationship to the Contacts module. 

The desired outcome is for it to be a multienum to allow the user to select multiple brands via the dropdown of which, on save, will each be related to the Contact rather than just a single brand which the default relate field provides.

I realise this can be done via the subpanels by linking existing records however the multi-select is dynamic in that it is populated by Javascript with particular values so we'd like it to be a multi enum on the form itself. Essentially when the user selects from the 'Accounts' relate field it then populates the 'Brands' dropdown with the related brands (it also filters based on a few other custom fields) to that account. The same thing happens for another multi select on the page as well after 1 or more brands are chosen. 

I have so far tried simply adding a relate field to the page through studio and then altering the vardefs by setting the type to 'multienum' and setting 'isMultiSelect' to true but this doesn't seem to work. You can select multiple brands but you don't seem to be able to edit the field after that and the overall save fails. I'm wondering if anyone has tried to achieve this before.

I am using Sugar 7.9.0.

Any help would be appreciated. 

Thanks,

Steve

  • Hi Steve Rose 

    As far I understand you want to choose Brand records from a multienum field in a module record, right? And the list of Brand to be displayed on that multienum field is filtered by some other criteria, like Brands assigned to the related Account, right?

    If I properly got the idea, your request is not easy to implement, although it is possible to.

    Let me know if I got the big picture so I can try helping you.

    Kind regards

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

    Yea pretty much.

    It's basically trying to achieve what 'Link to existing records' does but via a multienum so theoretically as a user a sample flow would be:
    1) Create a contact

    2) Select an account

    3) Select one or more brands from the multi enum (populated based on your 'Account' selection) to relate to the Contact.

    4) Save.

    So far I have it so the brands multi select populates based on the Account but its whether that can be turned into a relate field so any brands that are selected would each be related to the Contact.

  • Just to be transparent this is an alternative I have considered which may or may not be slightly easier to implement.

    A work around could be that on create of a contact when the user clicks 'Save' the page goes straight to the 'Link to existing records' page (which the user could get to via the button in the Brands subpanel) and a custom filter is applied to it (if that is possible) so they are prompted to add related brands. This would therefore be using Sugars 'out the box' mass apply screen with some slight customisations instead of the multi select.

    Just a thought in case what I'm trying to do isn't achievable.  

  • Copy the attached zip into custom/clients/base/fields and uncompress it.

    Create a regular multienum field on module Contacts and add it into record view.

    Create a custom endpoint which will return a list of Brands assigned to a given Account. The endpoint url should be something like that:

    Accounts/brand_list/<AccountID>

    The endpoint definition in the method registerApiRest of your custom endpoint class must looks like that:

                'getBrandList' => array(

                    'reqType' => 'GET',

                    'path' => array('Accounts', 'brand_list', '?'),

                    'pathVars' => array('', '', 'account_id'),

                    'method' => 'getBrandList',

                    'shortHelp' => 'Get a list of Brands for a multi-select field',

                    'longHelp' => '',

                ),

    In the custom record view of Contacts edit the new multienum field in order to add the following attributes:

    'type' => 'enum-parent-api',
    'api' => 'Accounts/brand_list/',
    'parent' => 'account_id',

    Update the attribute 'api' with the endpoint from where you will fetch Brands assigned to the Account related to the current Contact. This endpoint must return a regular dropdown array.

    Update the attribute 'parent' with the name of account field, like account_id.

    Go to Admin -> Repair -> "Quick Repair and Rebuild" and Admin -> Repair -> Clear additional Cache

    I hope this helps you

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • This was very helpful! 

    There were some things in the JS code I hadn't considered doing which are done here so will be useful going forwards as well as I work with Sugar more. 

    This appears to have fixed my issue I was facing when I bought it into my code. Certainly a lot more complicated than I initially thought though but good to have it working. 

    Thank you for the help and quick response!

    Steve

  • Hi @AndreLope and Steve Rose

    i want custom like that but i am new in sugarcrm can you give me reverence step by step , like create endPoint URL , and what file must add custom file.

    thanks 

    regards Eka Indra

  • Hello!  I am just curious do you know if this fix is mobile app friendly?