Announcement

Collapse
No announcement yet.

Custom primary filter for multi-enum

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

  • rabii
    commented on 's reply
    Hi @bandtank

    The filters allow you to have primary filter on list view of certain entity. it is powerful way to filter data based on conditions also you can add more user restrictions if you wish to. using advanced pack you can build filter reports but i prefer to use these custom filters as i can use them on dashlets as well. you can find the whole process of creating custom filters on this blog post here https://devcrm.it/custom-filters

    i hope you find it helpful if you need it in future.

  • bandtank
    replied
    Originally posted by item View Post
    first Hi, (with my poor english)

    https://github.com/espocrm/espocrm/b...s/Account.json

    in metadata you declare wich and where you select class is

    then in path of rabii have posted, you implement ...

    and for language file.. i don't know but easy to find..

    I use on github "search/find" .. and try to replicate
    Thanks. That helps a lot, actually. I don't see a need for primary filters after looking at the code in the repository because the advanced pack allows reports to be used as filters. It's good to know how to do it, though.

    Leave a comment:


  • item
    replied
    first Hi, (with my poor english)



    in metadata you declare wich and where you select class is

    then in path of rabii have posted, you implement ...

    and for language file.. i don't know but easy to find..

    I use on github "search/find" .. and try to replicate

    Leave a comment:


  • bandtank
    replied
    Originally posted by item View Post
    Hi bandtank,

    https://docs.espocrm.com/development...erclassnamemap

    in V6? or V7 Yuri have do so
    I do not know what to do with the information at that link. I found it, but how is it implemented? Which files? The information is helpful, but only if you already know what to do. A complete guide would be better and I think it would only be a few sentences to explain the details.

    Leave a comment:


  • item
    replied
    Hi bandtank,

    https://docs.espocrm.com/development...erclassnamemap

    in V6? or V7 Yuri have do so

    Leave a comment:


  • bandtank
    replied
    rabii How does this filter fit into the entire process? What calls it? Is it automatically used or is there more code in another file? Also, what does it do?

    I'm wondering if this is a special namespace: Espo\Custom\Classes\Select\Account\PrimaryFilters

    Leave a comment:


  • emillod
    commented on 's reply
    you right. I'm sorry. I didn't noticed that.

  • espcrm
    commented on 's reply
    I mean that just fieldname isn't it? Otherwise the 'syntax' is all good like yours... My coding skill is next to the trash can so I can't tell where the error is.

    UPDATE: OK, I totally didn't see that double = sign.
    Last edited by espcrm; 04-05-2022, 09:42 AM.

  • item
    commented on 's reply
    Yes, it will help many

  • rabii
    replied
    item thanks for your reply i already tried your solution before posting here and it didn't work because that solution would only work for enum and in my case i am using multi-enum which treated differently, big thanks to yuri who helped me sort it out, there are two ways to achieve this see both code below:

    Code:
    <?php
    
    namespace Espo\Custom\Classes\Select\Account\PrimaryFilters;
    
    use Espo\Core\Select\Primary\Filter;
    use Espo\ORM\Query\SelectBuilder;
    use Espo\Core\Select\Where\ConverterFactory;
    use Espo\Entities\User;
    
    class PartnerClients implements Filter
    {
    private $converterFactory;
    private $user;
    public function __construct(ConverterFactory $converterFactory, User $user){
    $this->converterFactory = $converterFactory;
    $this->user = $user;
    }
    public function apply(SelectBuilder $queryBuilder): void
    {
    $converter = $this->converterFactory->create('Account', $this->user);
    $whereClause = $converter->convert(
    $queryBuilder,
    (new \Espo\Core\Select\Where\ItemBuilder)
    ->setAttribute('accountType')
    ->setType('arrayAllOf')
    ->setValue(['Client', 'Introducer'])
    ->build()
    );
    $queryBuilder->where($whereClause);
    }
    }
    Second way to achieve this below (both ways works) - second way allow to give more specific conditions e.g only accountType (Introducer):

    Code:
    <?php
    
    namespace Espo\Custom\Classes\Select\Account\PrimaryFilters;
    
    use Espo\Core\Select\Primary\Filter;
    use Espo\ORM\Query\SelectBuilder;
    use Espo\ORM\Query\Part\Condition as Cond;
    
    class OnlyActiveIntroducers implements Filter
    {
    public function apply(SelectBuilder $queryBuilder): void
    {
    $introducer = SelectBuilder::create()
    ->from('ArrayValue')
    ->select('entityId')
    ->where([
    'value' => 'Introducer',
    'attribute' => 'accountType',
    'entityType' => 'Account',
    'deleted' => false,
    ])
    ->build();
    
    $notClient = SelectBuilder::create()
    ->from('ArrayValue')
    ->select('entityId')
    ->where([
    'value' => 'Client',
    'attribute' => 'accountType',
    'entityType' => 'Account',
    'deleted' => false,
    ])
    ->build();
    
    $notAccountant = SelectBuilder::create()
    ->from('ArrayValue')
    ->select('entityId')
    ->where([
    'value' => 'Accountant',
    'attribute' => 'accountType',
    'entityType' => 'Account',
    'deleted' => false,
    ])
    ->build();
    
    $queryBuilder
    ->where(
    Cond::and(
    Cond::in(Cond::column('id'), $introducer),
    Cond::notIn(Cond::column('id'), $notClient),
    Cond::notIn(Cond::column('id'), $notAccountant),
    Cond::in(Cond::column('state'), ['Active']),
    )
    );
    }
    }
    I hope this help someone.
    Thank you guys for your support, i love this community.

    Leave a comment:


  • item
    replied
    Hi,
    your sample is for enum field, not for multi-enum
    see on GitHub closed issue where Yuri have post solution

    Is your feature request related to a problem? Please describe. I have a multi-enum field called (companyType) on account entity and i created a primary filter (Client Introducers) for my account en...

    Leave a comment:


  • emillod
    replied
    espcrm he posted
    'companyType' =>

    And mine example:
    'status=' =>


    Leave a comment:


  • espcrm
    commented on 's reply
    I don't see the difference between yours code (symbol) and his.

    His "=" sign is same position as yours, everything else seem same also.

  • emillod
    replied
    Hello rabii

    please use this:
    PHP Code:
    $queryBuilder->where([
    'status=' => ['Active''Closed']
    ]); 
    You simply forgot about sign = next to field name

    Leave a comment:


  • rabii
    started a topic Custom primary filter for multi-enum

    Custom primary filter for multi-enum

    I have created a custom primary filter but it is not working, i don't know how to get values for a multi-enum field, below code doesn't work. anyone knows how to get value for multi-enum field using the SelectBuilder :

    Code:
    <?php
    
    namespace Espo\Custom\Classes\Select\Account\PrimaryFilters;
    
    use Espo\Core\Select\Primary\Filter;
    use Espo\ORM\Query\SelectBuilder;
    
    class Clients implements Filter
    {
    public function apply(SelectBuilder $queryBuilder): void
    {
    $queryBuilder->where([
    'companyType' => ['Client', 'Introducer'],
    ]);
    }
    }
    the companyType is a multi-enum field so i am trying get the companyType values both Client and Introducer.

    Thanks
Working...
X