Default filter for all users

Hi,

How can i create a generic filter that automatically open by default in the browser screen for all users of the application?

I tried setting and saving a generic filter as default and available to all users using the ‘admin’ user login, but it worked for the ‘admin’ user only.

1 Like

Hi,

At first, please see the “Screen invocation parameters” section in the documentation.

When you create a new Filter a new sec$Filter entity is created, it is stored in the database in the sec_filter table.
So filters could be modified by the use of DB management tool or Entity Inspector (select Filter (sec$Filter) on the Administration->Entity Inspector screen).

  1. Login by user with the cuba.gui.filter.global permission (admin).

  2. Open target screen. Create a filter and make it available for all users. It means that the value of the user_id column in the sec_filter table is NULL.

  3. Using Entity Inspector (or DB tool) specify the Code of the filter. On production it is recommended to create a filter with the 30.create-db.sql init script

  4. After the filter with certain code is created you should adjust the screen to use it by default.

Open the MAIN MENU tab in navigation panel in Studio.

Press Edit and choose the screen.

Open Params editor.

Add a new parameter. The name is the ID of the Filter component, and value is the code of the created filter.

As a result, web-menu.xml should have something similar to:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<menu-config xmlns="http://schemas.haulmont.com/cuba/menu.xsd">
    <menu id="application"
          insertBefore="administration">
    
        <item id="relatedentites$Customer.browse">
            <param name="filter"
                   value="12345"/>
        </item>
        <item id="relatedentites$Operator.browse"></item>
....
    </menu>
</menu-config>

After this actions, the created filter will be applied by default when the screen is opened.

Regards.

studio

Hi Rostislav,

as this (and similar) requests come up quite often, would it be possible to automate something like this through studio? Like creating a standard filter, defining the code in studio and placing the result in the sql file as well as adjusting the xml screen? Or do you think this is out of scope?

Bye
Mario

Thanks Rostislav for the steps to do this. My apologies for missing out on the doc at the end of the filter section.

Would be great if some automation can make it easier to set up as mentioned by Mario. Also, not sure if it’s possible to enhance the save filter with a new option to it make default to all users.

Hi,

The default filter for a screen is stored in the user personal settings. So at runtime, it is hard to make a filter default for all users: new users can be created later.

There is a chance to simplify the script creation: insert-script for particular entity instance can be got from System Information.
For the Filter entity:

  1. Open the Entity inspector (Administration-Entity Inspector).
  2. Select the Filter (sec$Filter) entity.
  3. In the table select the required filter and click on it by the right mouse button(see the attached screenshot).
  4. In the context menu choose System Information. And click the “Script for insert” button.

You can copy the code and paste it to the 30.create-db.sql init script. It might be done in Studio (via DB manager).

insertScript

Hi,

Regarding filters, I think, the created filter should be tested before to add it to DB-scripts. So it is better to create it at runtime and to generate the SQL script as I described above

Anyway, you can create a topic with the “idea” type and vote for it.

Regards.

Hi guys,

We will think about simplifying this task - I’ve created a YouTrack issue.

2 Likes

Hi,
I have the same problem. So I have that filter script. Should I just insert it into 30.create-db.sql init script and run it? That’s all? What if it won’t work? Can it redo/undo?
It will seen for admins and other rule members too? To run that script, update database is enough? I am afraid of if I recreate the database, the database values will lost.

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-8423

A post was split to a new topic: Default filter for all users with tenancy management