Passing Filter Criteria to proc

markcle
Member Posts: 65
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
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
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
0
Best Answer
-
You need to operate on multiple records from one table I presume.
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);
5
Answers
-
Thanks for reply, but that leaves same duplicate code to apply all the filters and there will often be more than one record (hence the DeleteAll0
-
Pass the record variable as VAR(!). That is different from just passing a line of fields in a table.
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.0 -
Thanks for reply, but I need to operate on multiple records, so unless I can pass a filterset or something like a recordset (ADO), I don't see how this would work (or am i missing something)0
-
You need to operate on multiple records from one table I presume.
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);
5 -
Thanks. That's what I was hoping. Will give it a shot0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions