Open lookup with special query


I have to open sales table when in customer’s browser screen one row has selected, and clicked my button. My problem is, when I open sales I need to filter/query for the selected customer row in sales, to show only selected customer’s sales.

So I would need a query like this:

select e from myproject$sales e where e.customer = selectedCustomer

I do not really know JPQL.

And I do not know how to pass it through openLookup().

My function:

public void openCustomersSales(Component component) {
        Sales s = salesTable.getSingleSelected();
        if (s != null) {
        	Customer c = metadata.create(Customer.class);
            openLookup(c, handler,WindowManager.OpenType.THIS_TAB, params); //May I should pass the new query with params?
        } else {
            showNotification("Please select a row to copy", NotificationType.HUMANIZED);

First of all, you need to open the corresponding screen. In your case Sales browser (or lookup if you have a special one). So, specify window alias as the first parameter, e.g.

openLookup("myproject$Sales.browse", handler, WindowManager.OpenType.THIS_TAB, params);

As the parameters value, you need to specify the selected customer (as far as I understand you need to filter sales by selected customer), e.g.

openLookup("myproject$Sales.browse", handler, WindowManager.OpenType.DIALOG,
                ParamsMap.of("customer", customersTable.getSingleSelected()));

And the last thing, you need to add a filter for sales’ query. A JPQL query in a datasource may contain parameters of several types. In your case, you need to use the param prefix (see the doc link for a description), e.g.

	<!&#91;CDATA&#91;select e from myproject$sales e&#93;&#93;>
			<c> = :param$customer</c>

I’ve prepared a sample project at GitHub.


Thank you so much.
What I want is to guide the user from Customers to Sales screen like user would select the Sales from the menu, and show to user the selected Customer’s Sales. This is why I need that button.
So on Sales I do not need “Selected” and “Cancel” buttons on the bottom of the screen. It should be like user select it from the menu, except user sees only selectes customer’s sales. Maybe a “back” button, but here at Sales, user should edit, create and delete the selected Customer’s sales.
How to do it? A ‘back’ button?

So I do not need a Lookup.Handler. On Sales, user do the usual things, edit, create etc. User do not Select. How to not to call lookup handler?


In this case, ou can use the openWindow method instead with either OpenType.THIS_TAB (and use breadcrumbs to navigate back to the customer’s browser) or OpenType.NEW_TAB.

1 Like