Change existing enum field to multi enum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nishan Perera
    Active Community Member
    • Jan 2019
    • 348

    Change existing enum field to multi enum

    Hi,

    Is it possible to change existing enum field to multi enum field ??
    Cheers!
    Nishan.
  • eymen-elkum
    Active Community Member
    • Nov 2014
    • 472

    #2
    yes it is possible by two ways,

    The best is to edit the file manually, you can find the definiation of the field in one of these pathes:
    • 'corePath' => 'application/Espo/Resources/metadata/entityDefs/YourEntity.json',
    • 'modulePath' => 'application/Espo/Modules/{*}/Resources/metadata/entityDefs/YourEntity.json',
    • 'customPath' => 'custom/Espo/Custom/Resources/metadata/entityDefs/YourEntity.json',
    Then you search for your filed block in the json and only replace the type value from enum to multiEnum, this is an example.

    Or if you dont have access to the files you can remove the field and re-add a new field with THE SAME NAME, espocrm will not remove the column from the database, so that the values will remain with the new field.

    Please give me feedback for other users
    CEO of Eblasoft
    EspoCRM Expert since 2014
    Full Stack Web Developer since 2008
    Creator of Numerous Successful Extensions & Projects​

    Comment

    • esforim
      Active Community Member
      • Jan 2020
      • 2204

      #3
      Never knew about the "remove field name" trick. That is good to know. Adding this to Learning EspoCRM.

      But question is, it won't work for all field right? e.g you can't delete a varchar field and create a new intreger field. But something that is similar can be done, e.g. eNum > multiEnum?

      Comment


      • eymen-elkum
        eymen-elkum commented
        Editing a comment
        Happy to let you learn new trick for espocrm,

        Yes this trick cannot help for all fields types,
    • Nishan Perera
      Active Community Member
      • Jan 2019
      • 348

      #4
      Originally posted by espcrm
      Never knew about the "remove field name" trick. That is good to know. Adding this to Learning EspoCRM.

      But question is, it won't work for all field right? e.g you can't delete a varchar field and create a new intreger field. But something that is similar can be done, e.g. eNum > multiEnum?
      Yes true. This can be done with similar fields like you said.
      Cheers!
      Nishan.

      Comment

      • esforim
        Active Community Member
        • Jan 2020
        • 2204

        #5
        Would you happens to know which type of field is compatibility?

        If the field type is the same, I assume it always will work. But certain field must have similar type to use this method.

        Comment

        • nicko
          Junior Member
          • Apr 2020
          • 29

          #6
          Hello, I thought i'd give some feedback - i needed to do this for a field and tried it for changing enum to multiEnum for the type field in the Contacts entity, but found that after the change (editing the json), where there had been a value in the Type field this was now blank. So it looks like it does work, but you lose your existing data,
          So I can retain the data I'm going to try exporting record ID and the type field, then import back in after the change.

          Comment


          • shalmaxb
            shalmaxb commented
            Editing a comment
            Did you execute rebuild? I guess that would be necessary to connect the database again to the new created field
        • nicko
          Junior Member
          • Apr 2020
          • 29

          #7
          Hey shalmaxb, thanks for the reply, yep I did try a rebuild, the field is just empty after making the change to multienum. It shows correctly in Entity manager as multi-enum, so change has taken effect ok. I guess the format of the object in the backend DB for enum vs multi-enum is different. No worries, I will go with the option of doing export/import.

          Comment

          • telecastg
            Active Community Member
            • Jun 2018
            • 907

            #8
            FYI enum and multienun are both stored by the database as varchar, but their contents are two different things:

            Enum fields are stored as simple varchar value corresponding to the choice selected in the enum field display.

            For example, assuming that you have an enum field with the choices: "Option 1", "Option 2" and "Option 3" and you select "Option 3", the varchar field in the table will have the string "Option 3"

            Multi-enum fields are stored as an array inside de varchar, with one element for each choice selected in the multi-enum field display.

            Asuming that you have a multi-enum field with the same choices as above, and you select "Option 1" and Option 3", the varchar content will be "[Option 1, Option 3]"

            Hope this helps clarifying.

            Comment

            • nicko
              Junior Member
              • Apr 2020
              • 29

              #9
              I had wondered if that was the case but didnt have chance to check the backend DB. Makes sense. Thanks telecastg

              Comment


              • telecastg
                telecastg commented
                Editing a comment
                You are welcome
            Working...