Announcement

Collapse
No announcement yet.

show in listing only active entries

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

  • show in listing only active entries

    We have a field "Active" in our customer data (account entity). Is there a way to display only the active entries in List view by default?

    Thanks for your help

  • #2
    what do you mean field (Active) is this a boolean ? also do you mean to show all active customers on both list view and listSmall view ?

    If yes then it is possible with few line of codes
    Rabii
    Web Dev

    Comment


    • #3
      Hello rabii,
      thanks for your reply.
      Yes, we have a boolean field in accounts. And yes, we want that in all list views only show entries with the boolean field marked as "active".

      Comment


      • #4
        You could do that also by a search filter

        Comment


        • #5
          Simple way (you need to display the Active field in Administration > Entity Manager > Account > Layouts > Search Filters)

          Click image for larger version

Name:	1.png
Views:	313
Size:	37.0 KB
ID:	95710
          Complex way (Report filter with EspoCRM file editing): https://forum.espocrm.com/forum/feat...2689#post92689

          Comment


          • #6
            Originally posted by pehoma View Post
            Hello rabii,
            thanks for your reply.
            Yes, we have a boolean field in accounts. And yes, we want that in all list views only show entries with the boolean field marked as "active".
            you need to do this, first create a primary filter for the boolean field (not sure what is the name of the field but i will name it isActive for this example), follow steps below to achieve this:

            1 - Create a file under Espo\Custom\Classes\Select\Account\PrimaryFilters\ Active (Active.php) (Remember to change the name of the field to the correct name you have in your instance

            PHP Code:
            <?php

            namespace Espo\Custom\Classes\Select\Account\PrimaryFilters;

            use 
            Espo\Core\Select\Primary\Filter;
            use 
            Espo\ORM\Query\SelectBuilder;

            class 
            Active implements Filter
            {
                public function 
            apply(SelectBuilder $queryBuilder): void
                
            {
                    
            $queryBuilder->where([
                        
            'isActive' => true,
                    ]);
                }
            }

            2 - Create a file Account.json under (Espo\Custom\Resources\metadata\selectDefs\Account .json)
            PHP Code:
            {
                
            "primaryFilterClassNameMap": {
                    
            "active""Espo\\Custom\\Classes\\Select\\Account\\PrimaryFilters\\Active"
                
            }
            }
            ​ 

            3 - Create or Add this to Account.json (if already exist) under (Espo\Custom\Resources\metadata\clientDefs\Account .json)
            PHP Code:
            {
                
            "filterList": [
                    
            "__APPEND__",
                    
            "active",
                    {
                        
            "name""active",
                        
            "style""success"
                    
            }
                ],
                
            "defaultFilterData": {
                    
            "primary""active"
                
            }
            }
            ​ 
            Clear cache and rebuild the system and the active filter will be set by default for the list view.

            Hope this helps.
            Rabii
            Web Dev

            Comment


            • #7
              rabii Attached are the screenshots for reference.
              • Screenshot 1: In the "Account" entity, I’m creating an "Opportunity" from the bottom panel. When mapping a related Contact to the "Opportunity", I see only the related "Contacts" for the "Account" in the default filter, which is working as expected.
              • Screenshot 2: In the "Dealer" entity (a custom entity of type "Company"), I don’t get the same behaviour. Instead of showing only the related "Contacts" for this "Dealer", it shows all "Contact" records.

              I would like to replicate the same behaviour for the "Dealer" entity, so that only related "Contacts" appear when mapping. Could you guide me on how to achieve this? Should I use a report filter or a select handler? I have raised this issue previously as well, but I am still unable to resolve it.

              Comment


              • #8
                Hey Ashif Malayil

                Because in your custom entity Dealer you need to provide a custom filter for the contacts field Or just use an already existing selecthandler that will do the same job (luckly espocrm provides few out of the box). Here is what you need to do go to your custom/Espo/Custom/Resources/metadata/clientDefs/Dealer.js and just add this line to the contacts on relationship as below

                PHP Code:
                "relationshipPanels": {
                        
                "contacts": {
                            
                "selectHandler""handlers/select-related/same-account-many" // This is the line you need to add ad the end of your contacts
                        
                }


                Please remove my comment above and only add
                Code:
                "selectHandler": "handlers/select-related/same-account-many"
                otherwise json will through an error

                NB: It is important that the account link on the Dealer is called account and accountId otherwise the above wouldn't work and you need to customise your own select handler.

                Once done, clear_cache and then rebuild the system and it should work
                Last edited by rabii; 10-31-2024, 02:27 PM.
                Rabii
                Web Dev

                Comment


                • rabii
                  rabii commented
                  Editing a comment
                  you should add this to the Opportunity and not Dealer.js

                  It is your mistake you didn't share the correct info. i didn't know that Dealer has many opportunities.

              • #9
                Hi rabii,

                I have customised my own select handler:-

                client/src/handlers/select-related/same-dealer-many.js

                /************************************************** **********************
                * This file is part of EspoCRM.
                *
                * EspoCRM – Open Source CRM application.
                * Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
                * Website: https://www.espocrm.com
                *
                * This program is free software: you can redistribute it and/or modify
                * it under the terms of the GNU Affero General Public License as published by
                * the Free Software Foundation, either version 3 of the License, or
                * (at your option) any later version.
                *
                * This program is distributed in the hope that it will be useful,
                * but WITHOUT ANY WARRANTY; without even the implied warranty of
                * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
                * GNU Affero General Public License for more details.
                *
                * You should have received a copy of the GNU Affero General Public License
                * along with this program. If not, see <https://www.gnu.org/licenses/>.
                *
                * The interactive user interfaces in modified source and object code versions
                * of this program must display Appropriate Legal Notices, as required under
                * Section 5 of the GNU Affero General Public License version 3.
                *
                * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
                * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
                ************************************************** **********************/

                import SelectRelatedHandler from 'handlers/select-related';

                class SameDealerManySelectRelatedHandler extends SelectRelatedHandler {

                /**
                * @param {module:model} model
                * @return {Promise<module:handlers/select-related~filters>}
                */
                getFilters(model) {
                const advanced = {};

                let dealerId = null;
                let dealerName = null;

                if (model.get('dealerId')) {
                dealerId = model.get('dealerId');
                dealerName = model.get('dealerName');
                }

                if (!dealerId && model.get('parentType') === 'Dealer' && model.get('parentId')) {
                dealerId = model.get('parentId');
                dealerName = model.get('parentName');
                }

                if (dealerId) {
                const nameHash = {};
                nameHash[dealerId] = dealerName;

                advanced.dealers = {
                field: 'dealers',
                type: 'linkedWith',
                value: [dealerId],
                data: {nameHash: nameHash},
                };
                }

                return Promise.resolve({
                advanced: advanced,
                });
                }
                }

                // noinspection JSUnusedGlobalSymbols
                export default SameDealerManySelectRelatedHandler;



                Then, i added the file inside custom/Espo/Custom/Resources/metadata/clientDefs/Dealer.js

                "contacts": {
                "layout": null,
                "selectPrimaryFilterName": null,
                "selectHandler": "handlers/select-related/same-dealer-many"
                },​



                Clear cache and Rebuild done from CLI and Administration. Still the filter is not coming for Dealer entity while choosing Contacts.
                Last edited by Ashif Malayil; 11-04-2024, 06:33 AM.

                Comment


                • #10
                  Hey,

                  I assume the custom handler is located under custom folder in your client folder. then you need to fix it as below

                  PHP Code:
                  "contacts": {
                     
                  "selectHandler""custom:handlers/select-related/same-dealer-many"
                  },​​ 

                  I assume the custom handler is located under client/custom/handlers/select-related (then you need fix as above) it should be custom:handlers/select-related/same-dealer-many

                  Just remove layout and selectPrimaryFilterName as you don't need them
                  Rabii
                  Web Dev

                  Comment


                  • #11
                    Hey,

                    This is the path where i created the custom handler.

                    client/src/handlers/select-related# ls
                    same-account.js same-account-many.js same-dealer-many.js


                    ​In this path (client/custom/handlers/select-related), I have a "modules" directory after custom.

                    client/custom# ls
                    modules


                    Then, in this path:
                    client/custom/modules/advanced/src/handlers# i don't have select-related directory.

                    However, I got confused with the paths?

                    Comment


                    • rabii
                      rabii commented
                      Editing a comment
                      in order for espocrm to get your custom code to work, this should be done via installable extension or via custom directories. keep it simple don't use modules directory as the system need to scan it as if an installable directory.

                      Keep it simple move your custom handler to client/custom/src/handlers/select-related (Create those folders if they don't exist)

                  • #12
                    Hey,

                    I'm not sure where I'm going wrong; this issue has been pending for quite a while. As per your instructions, I created the src, handlers, and select-related directories and added the js file inside them, but it’s still not working.

                    Could there be an issue with the relationship between the Dealer and Contact modules? Is there something specific in the handler script I should check, like a field name or other configuration?

                    Could you review the handler script to see if there’s anything I need to verify or adjust?

                    Also, I hope you're aware of my process. From the Dealer module, in the bottom panel, I am creating an Opportunity. While creating this Opportunity, I want to select a related Dealer contact person for this Opportunity.​
                    Last edited by Ashif Malayil; 11-04-2024, 10:16 AM.

                    Comment


                    • rabii
                      rabii commented
                      Editing a comment
                      The issues is clear you are using ES6 in your custom handler which will not work. Use AMD instead.

                  • #13
                    NOTE: Now, Creating and View List a Contact from bottom panel of Dealer is happening, But Selecting is not working. Please refer the attached screen shot.

                    Comment


                    • #14
                      Hey rabii,

                      The handler json i changed to AMD with the help pf chatgpt.

                      /************************************************** **********************
                      * This file is part of EspoCRM.
                      *
                      * EspoCRM – Open Source CRM application.
                      * Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
                      * Website: https://www.espocrm.com
                      *
                      * This program is free software: you can redistribute it and/or modify
                      * it under the terms of the GNU Affero General Public License as published by
                      * the Free Software Foundation, either version 3 of the License, or
                      * (at your option) any later version.
                      *
                      * This program is distributed in the hope that it will be useful,
                      * but WITHOUT ANY WARRANTY; without even the implied warranty of
                      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
                      * GNU Affero General Public License for more details.
                      *
                      * You should have received a copy of the GNU Affero General Public License
                      * along with this program. If not, see <https://www.gnu.org/licenses/>.
                      *
                      * The interactive user interfaces in modified source and object code versions
                      * of this program must display Appropriate Legal Notices, as required under
                      * Section 5 of the GNU Affero General Public License version 3.
                      *
                      * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
                      * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
                      ************************************************** **********************/

                      import SelectRelatedHandler from 'handlers/select-related';

                      class SameDealerManySelectRelatedHandler extends SelectRelatedHandler {

                      /**
                      * @param {module:model} model
                      * @return {Promise<module:handlers/select-related~filters>}
                      */
                      getFilters(model) {
                      const advanced = {};

                      let dealerId = null;
                      let dealerName = null;

                      if (model.get('dealerId')) {
                      dealerId = model.get('dealerId');
                      dealerName = model.get('dealerName');
                      }

                      if (!dealerId && model.get('parentType') === 'Dealer' && model.get('parentId')) {
                      dealerId = model.get('parentId');
                      dealerName = model.get('parentName');
                      }

                      if (dealerId) {
                      const nameHash = {};
                      nameHash[dealerId] = dealerName;

                      advanced.dealers = {
                      field: 'dealers',
                      type: 'linkedWith',
                      value: [dealerId],
                      data: {nameHash: nameHash},
                      };
                      }

                      return Promise.resolve({
                      advanced: advanced,
                      });
                      }
                      }

                      // noinspection JSUnusedGlobalSymbols
                      export default SameDealerManySelectRelatedHandler;

                      Still nothing changed?

                      Comment


                      • #15
                        Here is the code below, copy and paste and it should work fine

                        PHP Code:
                        define('custom:handlers/select-related/same-dealer-many', ['handlers/select-related'], Dep => {

                            return class extends 
                        Dep {
                                
                        /**
                                 * @param {module:model.Class} model
                                 * @return {Promise<module:handlers/select-related~filters>}
                                 */
                                
                        getFilters(model) {
                                    
                        let advanced = {};

                                    
                        let dealerId null;
                                    
                        let dealerName null;

                                    if (
                        model.get('dealerId')) {
                                        
                        dealerId model.get('dealerId');
                                        
                        dealerName model.get('dealerName');
                                    }

                                    if (!
                        dealerId && model.get('parentType') === 'Dealer' && model.get('parentId')) {
                                        
                        dealerId model.get('parentId');
                                        
                        dealerName model.get('parentName');
                                    }

                                    if (
                        dealerId) {
                                        
                        let nameHash = {};
                                        
                        nameHash[dealerId] = dealerName;

                                        
                        advanced.dealers = {
                                            
                        field'dealers',
                                            
                        type'linkedWith',
                                            
                        value: [dealerId],
                                            
                        data: {nameHashnameHash},
                                        };
                                    }

                                    return 
                        Promise.resolve({
                                        
                        advancedadvanced,
                                    });
                                }
                            }
                        });
                        ​ 
                        Rabii
                        Web Dev

                        Comment

                        Working...
                        X