Pass parameter to programmatically created EntityPicker

Hi!
In the report parameter creation page, when selecting ‘Entity’ as the parameter type, an entityPicker is opened to choose a single field from the specified dictionary.
It is created programmatically in the ParameterFieldCreator class within the createField method.

public Field createField(ReportInputParameter parameter) {
            boolean isLookup = Boolean.TRUE.equals(parameter.getLookup());
            MetaClass entityMetaClass = metadata.getClass(parameter.getEntityMetaClass());

            EntityPicker field = isLookup
                    ? createEntityComboBox(parameter, entityMetaClass)
                    : createEntityPicker();

            field.setMetaClass(entityMetaClass);

            EntityLookupAction pickerLookupAction = (EntityLookupAction) actions.create(EntityLookupAction.ID);
            field.addAction(pickerLookupAction);

            String parameterScreen = parameter.getScreen();

            if (StringUtils.isNotEmpty(parameterScreen)) {
                pickerLookupAction.setScreenId(parameterScreen);
            }

            Action entityClearAction = actions.create(EntityClearAction.ID);
            field.addAction(entityClearAction);

            return field;
        }

I’m overriding it, is it possible to pass a parameter to the opened Browse screen?

I’m using Jmix version: 1.5.3
Jmix Studio plugin version: 2.0.3-232
IntelliJ version: IntelliJ IDEA 2023.2.2 (Ultimate Edition)

Hello,

You can override SingleFieldCreator creation and add parameter passing to the screen. But this will affect all reports where EntityPicker or EntityComboBox is used.

Tell us in more detail what parameters need to be passed to the screen? It may be worth adjusting the settings when opening the screen in the controller itself.

Docs - Opening Screens :: Jmix Documentation

Regards,
Nikita

Hi!
I wanted to pass reportCode to browse screen. I’ve already accomplished this using setScreenOptionsSupplier. it’ll filter entity fields based on the report code in dictionary to prevent users from selecting incorrect fields for the entity parameter in the report.
Can my method of passing parameters be considered correct?

We recommend using setters in controllers, but implementation will require obtaining a screen instance, which will complicate the code.

Your method is also correct.

Thank you vm. Have a good day!