HOWTO: Change a dropdown field to a multiselect field

sugarcrmdevelopers —  May 5, 2011 — 9 Comments

I came across an interesting question by a poster on the forums today:

I’m fairly new to Sugar so forgive me if this is too simple of a question, but I need to turn one of the “out-of-the-box” fields into a Multi-Select. It currently is a drop-down. Can someone give me a quick example of how I would do that?

As many of you know this is not possible thru Studio or Module Builder, since once a field type is defined it cannot be changed. If this is a custom field you could always just add a new field type and migrate your data over, but this isn’t possible for the any of the out of the box fields in the application. So how can we get around this limitation?

Fortunately, a poster from SugarCRM Silver Partner Captivea stepped in with an upgrade-safe way to change the field type to multienum. Simply add the following two lines into a php file in the custom/Extension/modules/MODULE_NAME/Ext/Vardefs/ directory and do a Quick Rebuild and Repair.

After doing this, the given dropdown field should now be a multiselect field.

9 responses to HOWTO: Change a dropdown field to a multiselect field

  1. 

    Hi John,
    thanks for all. Can i ask something ? Why you don’t close de php tag ?
    Is there any tip who can help for when use a close tag and where not ?

    Cheers

  2. 

    As multiselect values are concatenated strings (e.g. VALUE1^,^VALUE2…), care needs to be taken here to ensure that the dropdown field length/size in the database is sufficient to contain the often longer multiselect values.

    Truncation of values can occur otherwise!

    This can be done by using:

    $dictionary[‘MODULE_NAME’][‘fields’][‘FIELD’][‘len’] = ‘255’;

    Change 255 to whatever length you require.

  3. 

    Hello,

    could someone provide an example of what to edit this code for this use:

    I want to make the ‘account type’ for the Accounts module a multi-select – and of course to be upgrade safe – this is great example here – but just not sure what to edit this with

    is Accounts meant to be upper case when replace ‘MODULE_NAME’ — and what is the difference here between fields and FIELD?

    thanks in advance.

    • 

       Sorry for the confusion on this. You’ll want substitute ‘Account’ for ‘MODULE_NAME’ and ‘account_type’ for ‘FIELD’ in the above example to make the fix.

  4. 

    Tried this out today on a 6.4.4 Enterprise instance and was disappointed to see that this guide results in the converted field becoming unusable on list view (both the main module list view and all subpanels). Seemed to work well enough, besides that.

  5. 

    If your field is already populated with data, you will need to add the multienum separator (^) to the existing data. For example, I modified the industry field in the Accounts module to be multi-select so in my database (mySQL), I must execute the following update statement in order to filter on the newly modified field.
    update accounts set industry=CONCAT(‘^’,industry,’^’) where industry != ”;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s