Report Filter

Hi,

What can be done if I need to set all the filters set through the report request form on another rec.
variable? How do we know that the user has set the filter on say 1 field/2 fields or so on?

To be very specific, there is a Purchase Header dataitem. Based on the filters set for this dataitem by
the user, I want to be able to set the same filters on the PurchaseRcptHdr record variable. Since not all the fields are the same in both these tables, how can this be done?

I read that you can do this using GETFILTER(S), but what if the user sets filters on say only 2 fields
in the first report run, 3 fields in the next run & so on? I need to get these filters set in the report request form & set it on another rec. variable. Is there a way out?

Thanks & Regards,
Anse

Check Filter value field by field.[:(]

You can do it more easily by putting the record in a recordreference and then going trought the fields with help of a fieldreference.

This is always quite a problem, since logially Navision can not do some magic interpretation of the way fields map fom ne table to another, though I guess something like TRANSFERFIELDS eg PurchRecHeader.TRANSFERFILTERS(PurchRetHeader) could be a sort of work around, but no such a function does not exist.

So as Jsark says field by field is the only real solution is field by field. Of course the issue arrises when the user manualy adds filters to the request window. To prevent them doing this, you can do this:

MyPurchReturnHeader.copyfilters(urchRetHeader);
PurchRecHeader.SETFILTER(“Field1”,PurchRetHeader.getfilter(“Field1”);
MyPurchReturnHeader.SETRANGE(“Field1”);
PurchRecHeader.SETFILTER(“Field2”,PurchRetHeader.getfilter(“Field2”);
MyPurchReturnHeader.SETRANGE(“Field2”);
PurchRecHeader.SETFILTER(“Field3”,PurchRetHeader.getfilter(“Field3”);
MyPurchReturnHeader.SETRANGE(“Field3”);
If MyPurchReturnHeader.GETFLTERS <> ‘’ then
Error(‘It is not possible to add %1 filters’,MyPurchReturnHeader.GETFLTERS);

this will at least prevent the user adding more filters.

Not sure what version you are using, but the report 10050 - Daily invoicing report, does something similar, it carries filters set on the sales invoice header to the sales credit memo header table.

“Sales Invoice Header”.COPYFILTER(“Posting Date”,“Sales Cr.Memo Header”.“Posting Date”);
“Sales Invoice Header”.COPYFILTER(“Bill-to Customer No.”,“Sales Cr.Memo Header”.“Bill-to Customer No.”);
“Sales Invoice Header”.COPYFILTER(“Salesperson Code”,“Sales Cr.Memo Header”.“Salesperson Code”);

Hope it helps

I finally found 15 minutes to make this little program (but I didn’t test it):

// transfer filters on “recSalesHeader” to “recSalesInvoiceHeader”
globals:
recSalesHeader as record 36
recSalesInvoiceHeader as record 112
rerSalesHeader as recordreference
rerSalesInvoiceHeader as recordreference
firSalesHeader as fieldreference
firSalesInvoiceHeader as fieldreference
recFieldSalesHeader as record “Field”
recFieldSalesInvoiceHeader as record “Field”

// put the records in a recordreference
rerSalesHeader.GETTABLE(recSalesHeader);
rerSalesInvoiceHeader.GETTABLE(recSalesInvoiceHeader);

// loop all fields of recSalesHeader
recFieldSalesHeader.RESET;
recFieldSalesHeader.SETRANGE(TableNo,rerSalesHeader.Number);
recFieldSalesHeader.SETRANGE(Class,recFieldSalesHeader.Class::Normal);
recFieldSalesHeader.SETRANGE(Enabled,TRUE);
IF recFieldSalesHeader.FIND(’-’) THEN
REPEAT
// if the field also exists in recSalesInvoiceHeader
// BTW: if you are sure the same fields exists in both tables with THE SAME ID’s, you can use:
// IF recFieldSalesInvoiceHeader.GET(rerFieldSalesInvoiceHeader.Number,recFieldSalesHeader.“No.”) THEN BEGIN
// instead of the RESET+SETRANGE+FIND
recFieldSalesInvoiceHeader.RESET;
recFieldSalesInvoiceHeader.SETRANGE(TableNo,rerFieldSalesInvoiceHeader.Number);
recFieldSalesInvoiceHeader.SETRANGE(Class,recFieldSalesInvoiceHeader.Class::Normal);
recFieldSalesInvoiceHeader.SETRANGE(Enabled,TRUE);
recFieldSalesInvoiceHeader.SETRANGE(FieldName,recFieldSalesHeader.FieldName);
recFieldSalesInvoiceHeader.SETRANGE(Type,recFieldSalesHeader.Type);
recFieldSalesInvoiceHeader.SETRANGE(Len,recFieldSalesHeader.Len);
IF recFieldSalesInvoiceHeader.FIND(’-’) THEN BEGIN
// the same field exists in both tables, so transfer the filter on it (if there is one)
IF firSalesHeader.GETFILTER <> ‘’ THEN BEGIN
firSalesHeader := rerSalesHeader.FIELD(recFieldSalesHeader.“No.”);
firSalesInvoiceHeader := rerSalesInvoiceHeader.FIELD(recFieldSalesInvoiceHeader.“No.”);
firSalesInvoiceHeader.SETFILTER(firSalesHeader.GETFILTER);
END;
END;
UNTIL recFieldSalesHeader.NEXT = 0;

// put the recordreference back into the record
rerSalesInvoiceHeader.SETTABLE(recSalesInvoiceHeader);

Hi,

Thanks a lot for all your inputs.

Kriki, I shall go through your code & get back to you in case of any doubts.

Thanks again.

Regards,

Anse