Setting table filters from codeunits?

Datapac
Member Posts: 97
This code works when I use it in the OnLooKup trigger of the 'No. field of a Customer tabel.
gvUser.GET(USERID);
IF gvUser."Sales Resp. Ctr. Filter" <> '' THEN BEGIN
Rec.SETCURRENTKEY("Responsibility Center");
Rec.FILTERGROUP(2);
Rec.SETFILTER("Responsibility Center", gvUser."Sales Resp. Ctr.Filter");
Rec..FILTERGROUP(0);
END;
However this filter is only applied AFTER the user does a lookup on the field. I need the filter triggered before the users even open the table.
So the question is if I want to put this code in a codeunit instead of in a table how do I reference the table data (Since I don't have a 'Rec' available)? I have tried settuping a global variable, gvCustomer that is of data type 'Record' and has a subtype 'Customer' table. So it looks like:
gvUser.GET(USERID);
IF gvUser."Sales Resp. Ctr. Filter" <> '' THEN BEGIN
gvCustomer.SETCURRENTKEY("Responsibility Center");
gvCustomer.FILTERGROUP(2);
gvCustomer.SETFILTER("Responsibility Center", gvUser."Sales Resp. Ctr. Filter");
gvCustomer.FILTERGROUP(0);
END;
However this runs error free but does not do anything.
Thanks.
gvUser.GET(USERID);
IF gvUser."Sales Resp. Ctr. Filter" <> '' THEN BEGIN
Rec.SETCURRENTKEY("Responsibility Center");
Rec.FILTERGROUP(2);
Rec.SETFILTER("Responsibility Center", gvUser."Sales Resp. Ctr.Filter");
Rec..FILTERGROUP(0);
END;
However this filter is only applied AFTER the user does a lookup on the field. I need the filter triggered before the users even open the table.
So the question is if I want to put this code in a codeunit instead of in a table how do I reference the table data (Since I don't have a 'Rec' available)? I have tried settuping a global variable, gvCustomer that is of data type 'Record' and has a subtype 'Customer' table. So it looks like:
gvUser.GET(USERID);
IF gvUser."Sales Resp. Ctr. Filter" <> '' THEN BEGIN
gvCustomer.SETCURRENTKEY("Responsibility Center");
gvCustomer.FILTERGROUP(2);
gvCustomer.SETFILTER("Responsibility Center", gvUser."Sales Resp. Ctr. Filter");
gvCustomer.FILTERGROUP(0);
END;
However this runs error free but does not do anything.
Thanks.
0
Comments
-
If you want set filter to form, you can use trigger OnOpen. This trigger is called when the form is opening and the Rec is created...0
-
Yeah, we are trying to avoid setting the filter in the forms as we believe there would be a maitainence issue over time and the risk of inapropriate access for some users.
The reason we want to set the filter in a codeunit is so we can put it in one place (e.g in the CompanyOpen function in the Application Management codeunit) where it will be applied for all users all the time no matter what form they use to access the table. Or course if it can't be done via a codeunit then we will need to look at useing forms. Thanks.0 -
If you put this code into codeunit, you only need modify the form to call this codeunit and pass the Rec to this codeunit. You are not able to "catch" opening of the form to set the filters on the form without modifying the form.0
-
Thanks. via Forms it is then.0
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