How to add a custom filter with custom enum field values?

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rabii
    commented on 's reply
    Hey Tanya,

    Could you please help, i am trying to achieve the following :

    i have created 3 entities : Clients - Services - Projects

    - Client Has Many Projects
    - Client Has Many Services
    - Projects Has Many Services

    I would want to create new project and once i choose the client for this projects then when selecting services for the projects i want to get only services of the client selected for current project, just like the existing relation between call - contacts and account. In the call entity when creating new call for a specific account then in the contacts field you can choose only contacts that belong to this current account. please see attached screenshot.

    this is the link to the question i put on the forum but had not response yet.

    Hi all, i have created 3 entities : Clients - Services - Projects - Client Has Many Projects - Client Has Many Services - Projects Has Many Services I would want to create new project and once i choose the client for this projects then when selecting services for the projects i want to get only services of the client


    can you please help

    Many thanks

  • theBuzzyCoder
    replied
    Figured out why it was not working. The reason was browser cache. Once I did reload with

    Code:
    Ctrl + Shift + r
    it started working. Thanks for the quick response tanya . Helped me a lot.

    Leave a comment:


  • tanya
    replied
    custom/Espo/Custom/Resources/metadata/clientDefs/Lead.json
    with your content
    Code:
    {
        "filterList": [
            {
                "name": "newLeads"
            }
        ]
    }
    And I have this filter in the list. Did you clear the cache?

    Leave a comment:


  • theBuzzyCoder
    replied
    It started working somehow!

    In Administrator when I got to label manager -> Lead -> presetFilters and change the value, where exactly is it updated.

    In database(if yes, please specify which table / field) or Lead.json
    Last edited by theBuzzyCoder; 02-07-2018, 01:36 PM.

    Leave a comment:


  • tanya
    replied
    Hello
    Check if your json files are valid (maybe it's a part of json, if not I see extra commas). And filter name has to be "name": "newLeads" (lower camel case)

    Leave a comment:


  • theBuzzyCoder
    replied
    Hi,

    I am trying to do the same with leads but its not working

    here's my code and path to file

    /home/user/projects/www/espocrm/custom/Espo/Custom/SelectManagers/Lead.php

    PHP Code:
    <?php
    namespace Espo\Custom\SelectManagers;
    
    use Espo\Modules\Crm\SelectManagers\Lead as LeadCrm;
    
    class Lead extends LeadCrm
    {
        protected function filterNewLeads(&$result)
        {
            $result['whereClause'][] = array(
                'status=' => 'New'
            );
        }
    }
    ?>

    /home/user/projects/www/espocrm/custom/Espo/Custom/Resources/metadata/clientDefs/Lead.json

    Code:
    {
        "filterList": [
            {
                "name": "newLeads"
            }
        ]
    }
    /home/codaxtr_user/projects/www/espocrm/custom/Espo/Custom/Resources/i18n/en_US/Lead.json

    Code:
    {
        "presetFilters": {
            "newLeads": "New Leads"
        }
    }
    The filter "New Leads" is not showing up in the Leads

    Last edited by theBuzzyCoder; 02-07-2018, 10:01 AM.

    Leave a comment:


  • wtconseil
    replied
    Oh thanks ! you're right !

    Really ... really .. thanks for your awesome support!
    everything is ok for me now :-))

    PHP Code:
        modified:   custom/Espo/Custom/Resources/i18n/fr_FR/Contact.json
        new file:   custom/Espo/Custom/Resources/metadata/clientDefs/Contact.json
        new file:   custom/Espo/Custom/Selectmanagers/Contact.php 
    
    :-)))

    Leave a comment:


  • tanya
    replied
    Hi

    you added to entityDefs, needs to clientDefs folder
    also check if custom/Espo/Custom/Resources/metadata/clientDefs/Contact.json is valid and is readable.

    Leave a comment:


  • wtconseil
    replied
    A small question :

    If i had my filter in => application/Espo/Modules/Crm/Resources/metadata/clientDefs/Contact.json
    PHP Code:
        "filterList": [
    -      "portalUsers"
    +      "portalUsers",
    +      "MyFilter"
        ] 
    
    => it's working

    but i was thinking i could add it in custom folder => custom/Espo/Custom/Resources/metadata/entityDefs/Contact.json
    i try to add
    PHP Code:
    "filterList": [
    -      "portalUsers"
    +      "portalUsers",
    +      "MyFilter"
        ] 
    
    but .. not working.

    any reason ?

    If i let it in application folder, maybe it will be replace but one of your file during an upgrade?

    Thanks

    Leave a comment:


  • rgcadavos
    replied
    Thanks a lot, tanya

    Leave a comment:


  • tanya
    replied
    of course, you can set it in custom/Espo/Custom/Resources/i18n/fr_FR/Contact.json

    Leave a comment:


  • wtconseil
    replied
    can we do the translate / presetFilters through "custom" folder (=> e.g. custom/Espo/Custom/Resources/i18n/fr_FR/Contact.json )

    or should we do that in application/Espo/Resources/i18n/fr_FR/Global.json ?

    Leave a comment:


  • tanya
    replied
    Hi
    Translation for this is in "presetFilters" section.
    Code:
    "presetFilters": {
            "customEnum": "custom - Enum"
        }

    Leave a comment:


  • rgcadavos
    replied
    Hi @tanya,

    By the way, thanks for the responses.

    I have added

    $this->applyOrder('note.modified_at', true, $result);
    $result['distinct'] = true;

    and it did return the correct total count and was sorted to the latest activity.

    here is my final code,

    Code:
    protected function filterEmailSent(&$result)
    {
    $result['customJoin'] .= " LEFT JOIN note ON contact.id = note.parent_id AND note.deleted = 0";
    $this->addAndWhere(array(
    'note.type' => 'EmailSent'
    ), $result);
    $this->applyOrder('note.modified_at', true, $result);
    $result['distinct'] = true;
    }
    protected function filterHasCall(&$result)
    {
    $result['customJoin'] .= " LEFT JOIN note ON contact.id = note.parent_id AND note.deleted = 0";
    $this->addAndWhere(array(
    'note.related_type' => 'Call'
    ), $result);
    $this->applyOrder('note.modified_at', true, $result);
    $result['distinct'] = true;
    }
    and Contact.json in clientdef,

    Code:
    "filterList": [
    {
    "name":"emailSent",
    "label":"Email Sent"
    },
    {
    "name":"hasCall",
    "label":"Has Call"
    }
    ]
    but the label doesnt work well when selected. Can you help? is this a bug?
    Last edited by rgcadavos; 03-16-2017, 03:33 PM.

    Leave a comment:


  • tanya
    replied
    application/Espo/ORM/DB/Query/Base.php method createSelectQuery
    add endpoint before return, like
    Code:
     if ($entityName == "Contact") { $GLOBALS['log']->error($sql);}
    run query from log file in phpMyAdmin and analyze, what you need to add to query (possible contact.id duplicates because of one of JOIN)

    Leave a comment:

Working...