Hi All
New to Nav and AL code and working on first extensions. It's all working, but now I'm factorizing my code
I have a case statement that repeats this code and want to factorize it
SalesLine.SETRANGE("Document Type", rec."Document Type");
SalesLine.SETRANGE("Document No.", rec."No.");
SalesLine.SETRANGE(Type, SalesLine.Type::Item);
SalesLine.SetFilter("No.", 'FJOB | FCOM | FRES | FLIFT');
DeleteAll(TRUE);
I presume I could just pass Doc Type, Doc No, Line Type and the String for the Setfilter as params, so it's more general purpose (the calling proc can supply any list of items)
I've read about Setfilter, GetFilter and FilterGroups and wondering if I can somehow pass the entire "filter" as a single object instead of 4 params
What would be the best way to factorize this?
Thanks
Mark
Answers
It contains the current record, but you do not have to 'find' or 'get' the record first.
You can use it to pass filters or anything else applied to it before it entered the function.
Try this:
SalesLine.SETRANGE("Document Type", rec."Document Type");
SalesLine.SETRANGE("Document No.", rec."No.");
SalesLine.SETRANGE(Type, SalesLine.Type::Item);
SalesLine.SetFilter("No.", 'FJOB | FCOM | FRES | FLIFT');
MyFunction(SalesLine);
LOCAL MyFunction(VAR SalesLineV: Record "Sales Line")
//now pass the entire "filter" as a single object to another intance of a sales line rec:
OtherSalesline.copy(SalesLineV);
MESSAGE('My filters: %1',OtherSalesline.getfilters);