LookupPickerField component with datasource narrow by column

Hi

I have LookupPickerField component with simple query like

select e from erp$table I need add where condition e.g

select e from erp$table where e.ledger.register= ....

I’d like get where value from field in editwindow. How can I do it ?
Where have I change datasource in browse controler or editwindow controler ?

.

I think this should work for editor:

@Inject
private CollectionDatasource<MyEntity, UUID> mydatasource;

Then add a change listener on desired field and add

mydatasource.setQuery(newQuery)
mydatasource.refresh();

mydatasource is the datasource you defined at layout xml.

I think this page might also have the information you’re looking for:

https://doc.cuba-platform.com/manual-latest/datasource_query_params.html

Your editor screen has a datasource which is linked to database record currently being shown. You can reference it in collection datasources like this:

select o from sales$Order o where o.customer.id = :ds$customersDs.id

The :ds$clause points to another datasource on the page. When the other data source changes (it points to a different record) then the SQL is run again and the options in your list will be updated.

Thanks both tips are working correctly.
In my case this datesource attach to optionsDatasource parameter.
I’d like attach the same query in browse which open from LookupPickerField. How can I do it ?

I think that the standard data sources can only be used on the page you declare them. (Someone will no doubt correct me if I’m wrong).

If you want to reuse a datasource then I think you’ll need to create a custom datasource class which you can reuse anywhere.

https://doc.cuba-platform.com/manual-latest/datasource_custom_class.html

If you look in Cuba Studio, where you define a data source, you have the option of selecting a custom class, instead of defining your JPQL statement.

You can pass a parameter map into the custom data source so that it can pick up changed values when it is refreshed.

A note for the Cuba folk:

Would it be useful to define a global data source xml file where you can define collection-based datasources that you want to reuse many places?

Ok but I think rather about way How I can avoid to create datasource ones for optionsDatasource second for browse window in open action. In my case
I can use e.g

action.setLookupScreenParams(ParamsMap.of(“register”,getItem().getLedger().getRegister().getId()));`

and in browse query I use notation

select e from erp$DocTypes e where e.register.id = :param$register