Report Filter based on SetSelectionFilter

If you want to print more than one document in a single report run from a List Page, you can use CurrPage.SETSELECTIONFILTER to set the filter on the dataset before you send it to a report. Like its done in Page 130 og Dynamics NAV 2017.

1

But what if you want to set the filter for related records from a different List Page?
Say you want to print all related Shipments from Sales Order List Page.
We can use the relation between Sales Order and the order no. saved on Shipment Header.

Create a Action on Sales Order List (Page 9305)
Create 3 local variables in the Action

2

Add the following code:

<Action1000000010> - OnAction()
//Get selected records in list
CurrPage.SETSELECTIONFILTER(SalesHeader);

// Loop records and create filtertext
IF SalesHeader.FINDFIRST THEN BEGIN
  REPEAT
    IF FilterText <> '' THEN BEGIN
      FilterText := FilterText + '|';
    END;
    FilterText := FilterText + SalesHeader."No.";
  UNTIL SalesHeader.NEXT = 0;
  CLEAR(SalesShptHeader);
  SalesShptHeader.SETFILTER("Order No.", FilterText);
  IF SalesShptHeader.FINDFIRST THEN BEGIN
    SalesShptHeader.PrintRecords(TRUE); //Print if any
  END ELSE BEGIN
    MESSAGE('No matching Shipments');
  END;
END;

Mark som Sales Orders and run the Action

3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s