Create Custom Filter to Cases

Hi Everyone!

I need to create a custom filter module for cases.

The "cases" module has a relationship with the "accounts" module, so the custom filter should show in my "cases" list view, only the records that its relationship with "accounts" its label "user assigned to" is equal to the current logged in user.

Actually I have this code:

global $current_user;
$viewdefs['Cases']['base']['filter']['basic']['filters'][] = array(
    'id' => 'filterCasesAccounts',
    'name' => 'LBL_FILTER_CASES_ACCOUNTS_TEMPLATE',
    'filter_definition' => array(
        array(
            'account_cases' => array(
                '$in' => array(
                    'assigned_user_id' => array(
                        '$equals' => $current_user->id,
                    ),
                ),
            ),
        ),
    ),
    'editable' => false,
    'is_template' => false,
);
How could I do this filter?
Thank you!
  • I didn't try that before, but perhaps it works:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    $viewdefs['Cases']['base']['filter']['basic']['filters'][] = array(
    'id' => 'filterCasesAccounts',
    'name' => 'LBL_FILTER_CASES_ACCOUNTS_TEMPLATE',
    'filter_definition' => array(
    array(
    '$owner' => 'accounts',
    ),
    ),
    'editable' => false,
    'is_template' => false,
    );
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Regargs

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi André.

    Thank you so much!
    Your code works succesfully, It was what I needed.

    Regards

  • Hi, do you need to do this because the same 'current user' is not the same as the Cases assigned to person?
    If yes, is it because they are the Account manager and this requirement is for them to have an overview of any Cases for their Accounts?
    No code solution exists for this if you or others are interested:

    Create a report based on Cases module, and use the filter that selects 'Current user'.
    Cases > Account > Assigned to User > User Name    


    This report is then easily added to Dashboards



    Hope that helps?

    .

    CRM Business Consultant

  • For anyone also trying to achieve this:

    '$owner' => ''

    works as well, seems more obvious, especially when not related to accounts module.

    Sugar also uses the following in some modules, not sure if this adds anything useful, but might be something to have a look at as well.

    '$owner' => array(
    'predefined_filter' => true,
    'vname' => 'LBL_CURRENT_USER_FILTER',
    )