Announcement

Collapse
No announcement yet.

How to adds fields with code?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to adds fields with code?

    Hello,

    I wanna add (with code) a INT field to User to set "Weight in Sales Distribution", with a value between 0 and 100.
    And I wanna add (with code) a CHECKBOX field to Teams to set "This team uses Weight of User".

    Logic: 1) I'll get the "This team uses Weight of User", if TRUE, I'll get all users and the value of "Weight in Sales Distribution". 2) I'll sum all and get the weight to send more leads to one user or other user.

    With Layout Manager and Entities I've solved, but I wanna do it with code.

    Anyone know how to do this in code?​

  • #2
    The layout manager and the entity manager "record" the changes that you made, in metadata json files, which are used by the system, upon "rebuilding", to create a metadata.php file that is used to keep track of all the system "switches" (configurable options).

    When you modify the core entities or layouts, the sytem creates metadata json files in the "Custom" namespace, which take precedent over other namespaces, so you can override any original setting with your own preferences.

    To see how it was done, in your example, check these files that should have been created by the system:

    custom/Espo/Custom/Resources/metadata/entityDefs/User.json
    this file will show the new field created for the User entity to set "Weight in Sales and Distribution"

    custom/Espo/Custom/Resources/metadata/entityDefs/Team.json
    this file will show the new field created in the Team entity to set "This team uses Weight of User"

    Assuming that you added those fields to the User and Team detail layout, the new fields will appear in the layout files:

    custom/Espo/Custom/Resources/layouts/User/detail.json
    custom/Espo/Custom/Resources/layouts/Team/detail.json

    If you are interested in learning more about some customizations via coding, this thread might help:
    https://forum.espocrm.com/forum/deve...ange-something

    Comment


    • #3
      Originally posted by telecastg View Post
      The layout manager and the entity manager "record" the changes that you made, in metadata json files, which are used by the system, upon "rebuilding", to create a metadata.php file that is used to keep track of all the system "switches" (configurable options).

      When you modify the core entities or layouts, the sytem creates metadata json files in the "Custom" namespace, which take precedent over other namespaces, so you can override any original setting with your own preferences.

      To see how it was done, in your example, check these files that should have been created by the system:

      custom/Espo/Custom/Resources/metadata/entityDefs/User.json
      this file will show the new field created for the User entity to set "Weight in Sales and Distribution"

      custom/Espo/Custom/Resources/metadata/entityDefs/Team.json
      this file will show the new field created in the Team entity to set "This team uses Weight of User"

      Assuming that you added those fields to the User and Team detail layout, the new fields will appear in the layout files:

      custom/Espo/Custom/Resources/layouts/User/detail.json
      custom/Espo/Custom/Resources/layouts/Team/detail.json

      If you are interested in learning more about some customizations via coding, this thread might help:
      https://forum.espocrm.com/forum/deve...ange-something
      You're amazing man! Thanks.

      I'm trying to package this in a extension (following the tutorial in link), but it's not working. Do you know how is the best way to package this?

      I've tried to put custom/Espo/Custom/Resources/*.* in files/application/Espo/Modules/WeightMod/Resources/*.* and tried to put in files/custom/Espo/Modules/WeightMod/Resources/*.*, but not working in both ways.

      (I added module.json in metadata folder).

      I sent it here (Weight Mod.zip).

      Thank you.
      Attached Files
      This tutorial describes how to create a simple extension based on a custom implementation and shows how to use 'Modules' to segregate customizations instead of having everything in the 'Custom' namespaces, making it much easier to manage changes and troubleshooting for your custom code. The custom implementation described here

      Comment


      • #4
        Hi,


        emillod have make a how to package as extension
        what you need, is just copy only your customisation on the same path in extension

        Comment


        • #5
          Originally posted by item View Post
          Hi,
          https://www.youtube.com/channel/UCZl...QQY43iQ/videos

          emillod have make a how to package as extension
          what you need, is just copy only your customisation on the same path in extension
          Thank you man!

          I'm newbie, I'm studying about EspoCRM since September and dont know everything.

          But I've a demand to use it in production.



          I've tried to solve by myself but I can't.

          I've tried to put custom/Espo/Custom/Resources/*.* in files/application/Espo/Modules/WeightMod/Resources/*.* and tried to put in files/custom/Espo/Modules/WeightMod/Resources/*.*, but not working in both ways.​

          Comment


          • #6
            I've tried to put custom/Espo/Custom/Resources/*.* in files/application/Espo/Modules/WeightMod/Resources/*.* and tried to put in files/custom/Espo/Modules/WeightMod/Resources/*.*, but not working in both ways.​​
            You will also need to let Espo know that the scopes (entities) User and Team have metadata definitions also in your new module, so you will need to create the following files (assuming that you are keeping the name spacing as custom.Espo/Modules/WeightMod/Resources/*.* :

            custom/Espo/Modules/Resources/metadata/scopes/User.json
            Code:
            {
                "module": "WeightMod"
            }​
            custom/Espo/Modules/Resources/metadata/scopes/Team.json
            Code:
            {
                "module": "WeightMod"
            }​

            Also be aware that once you put your scripts inside the module, all changes to them will have to be done manually.

            If you use the GUI Entity Manager or the Layout Manager Espo will create files in the "Custom" namespace only, so it will be possible to use these tools and everything will work, but in order to "maintain" your module, then you will need to copy and paste your modifications into the "twin" files inside the module and erase the Custom files.

            I'm newbie, I'm studying about EspoCRM since September and dont know everything.

            But I've a demand to use it in production.​
            Assuming that you are fairly proficient in Javascript and PHP, as your posting indicates, if you want to deep dive into Espo, I suggest that you become familiar, if you are not yet, with the framework backbone.js which is the foundation on which Espo was developed.


            Even though Espo is a leap over the original backbone library, and its GUI development tools are brilliant, its basic workflow structure is very similar to backbone's , thus understanding the role of views, models, collections, routing, API, etc will help a lot in understanding Espo.

            In regards to extensions, probably the best way to see how they are structured is to download the free Real Estate extension by Espo and study the file structure and the scripts contained there.
            Last edited by telecastg; 11-01-2022, 06:46 PM.

            Comment


            • #7
              Originally posted by telecastg View Post

              You will also need to let Espo know that the scopes (entities) User and Team have metadata definitions also in your new module, so you will need to create the following files (assuming that you are keeping the name spacing as custom.Espo/Modules/WeightMod/Resources/*.* :

              custom/Espo/Modules/Resources/metadata/scopes/User.json
              Code:
              {
              "module": "WeightMod"
              }​
              custom/Espo/Modules/Resources/metadata/scopes/Team.json
              Code:
              {
              "module": "WeightMod"
              }​

              Also be aware that once you put your scripts inside the module, all changes to them will have to be done manually.

              If you use the GUI Entity Manager or the Layout Manager Espo will create files in the "Custom" namespace only, so it will be possible to use these tools and everything will work, but in order to "maintain" your module, then you will need to copy and paste your modifications into the "twin" files inside the module and erase the Custom files.



              Assuming that you are fairly proficient in Javascript and PHP, as your posting indicates, if you want to deep dive into Espo, I suggest that you become familiar, if you are not yet, with the framework backbone.js which is the foundation on which Espo was developed.


              Even though Espo is a leap over the original backbone library, and its GUI development tools are brilliant, its basic workflow structure is very similar to backbone's , thus understanding the role of views, models, collections, routing, API, etc will help a lot in understanding Espo.

              In regards to extensions, probably the best way to see how they are structured is to download the free Real Estate extension by Espo and study the file structure and the scripts contained there.
              Really thank you for the answer.

              I made it and really work, the fields are in the Entity and Layout Manager, but the URL to create teams ("/#Admin/teams") is returning error 404.

              There are nothing in data/logs.

              What can I do to solve it?

              Comment


              • #8
                Hello,

                I tried a lot of things and I couldn't get it to work.

                The section /#Admin/teams return 404 error.

                I've attached here the extension.

                Someone can help me, please?

                In logs, I found this:

                Code:
                172.20.0.2 - - [10/Nov/2022:06:23:50 +0000] "GET /client/custom/modules/medya-mods/src/controllers/team.js HTTP/1.1" 404 518 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
                172.20.0.2 - - [10/Nov/2022:06:18:50 +0000] "GET /client/custom/modules/medya-mods/src/controllers/team.js?r=1668060790 HTTP/1.1" 404 518 "https://unicesumar-criciuma.medyadigital.com.br/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"​
                Attached Files
                Last edited by giuseppesilva; 11-10-2022, 06:28 AM.

                Comment


                • #9
                  Hello
                  here you have extension with solution of your problem.
                  This extension will build a fields, but you have to add them to layout by yourself.
                  Attached Files

                  Comment

                  Working...
                  X