Filtered OpenLookup based on previous drop-down field choice on edit screen.

I have an edit screen (see attached) in which I would like to make a selection in the first drop-down field, and use it as a filter or cascade for a drop-down selection on a second field, but also use this same first field selection as a filter when clicking the Lookup (…) button on the second LookupPickerField, so I only show items on the lookup/Select screen related to the first field selection (ex. Parts from only the selected Supplier). I’ve looked through various other forum articles, but I have not seen where there is an option for filtering a Lookup screen when clicking the Lookup(…) button on a LookupPickerField.

polinesEdit

Hello!

I suggest that you use the following method:

PickerField.LookupAction#setLookupScreenParamsSupplier

It will allow you to build a map that will contain the selected item each time when you invoke LookupAction. Then you can get this item from the map and filter entities.

Hi Daniil!

Thanks so much for the suggestion! I’m kind of new to this platform. Do you happen to know of any code examples that may show this implemented?

Thanks Again for your help!

I’ll prepare an example and share it with you later.

Sounds Great! Looking forward to your example!

So, first of all, you should build a window param map in your order editor screen:

// stores the chosen Supplier
@Inject
private LookupField supplierField;
// stores the chosen Product
@Inject
private LookupPickerField productField;

@Override
public void init(Map<String, Object> params) {
    productField.getLookupAction().setLookupScreenParamsSupplier(() ->
            ParamsMap.of("supplier", supplierField.getValue()));
}

Then you just need to save this param and filter items:

@Inject
private GroupDatasource<Product, UUID> productsDs;

private Supplier supplier;

@Override
public void init(Map<String, Object> params) {
    Supplier supplier = (Supplier) params.get("supplier");
    if (supplier != null) {
        this.supplier = supplier;
    }
}

@Override
public void ready() {
    if (supplier != null) {
        List<Product> allProducts = new ArrayList<>(productsDs.getItems());

        productsDs.clear();

        allProducts.stream()
                .filter(p -> p.getSupplier().equals(supplier))
                .forEach(productsDs::addItem);
    }
}

See also this sample application: https://github.com/cuba-platform/sample-screen-manipulation

This part is similar to your task:

> ProductBrowse screen modifies its datasource query depending on passed customer. If a customer is provided, the table shows only products for this customer and those without reference to a customer.

The implementation is here.

Gentlemen,

Thank you both! I have successfully implemented the desired functions using the methods you have both outlined above.

Thanks again for your Help!