Record Variable filtering

sarkie83
Member Posts: 22
This is part of the code i've added to the the Sales Line table - OnModify
It wasn't working as I hoped, so I put it in a report, to test the output but the COUNT value comes out at several thousand.
The code part in bold is where I need clarification..
SalesHeader.SETFILTER("No.","Document No.");
Is this selecting the No. field in SalesHeader and filtering where it = the Document No. in the current Sale Line?
btw SalesHeader is a record variable
Thanks,
Kieran
It wasn't working as I hoped, so I put it in a report, to test the output but the COUNT value comes out at several thousand.
SalesHeader.RESET; SalesHeader.SETCURRENTKEY("Document Type","No."); SalesHeader.SETFILTER("No.","Document No."); SalesHeader.SETRANGE("Holding Order",FALSE); SalesHeader.SETFILTER("Hold Code", '<> HELD'); IF SalesHeader.COUNT = 1 THEN ....(actions)...
The code part in bold is where I need clarification..
SalesHeader.SETFILTER("No.","Document No.");
Is this selecting the No. field in SalesHeader and filtering where it = the Document No. in the current Sale Line?
btw SalesHeader is a record variable
Thanks,
Kieran
0
Answers
-
Your approach is a bit off, in my opinion.
The primary key of the Sales Header table is "Document Type,No.". The primary key of the Sales Line table is "Document Type,Document No.,Line No.". These two tables are related where the Document Type fields are equal, and the "No." field in the Sales Header table is equal to the "Document No." field in the Sales Line table. Essentially this means that for each combination of "Document Type" and "Document No." (which uniquely identifies a Sales Header record), you can have an unlimited number of Sales Lines, and they are identified by the value of the "Line No." field.
So when you set a filter on the Sales Header on both the Document Type and the Document Number fields, you are uniquely identifying the Sales Header record. A better way to do this would be:SalesHeader.GET(SalesLine."Document Type",SalesLine."Document No.");
Then, instead of doing a COUNT, you can evaluate field values in the Sales Header record, something like this:IF (SalesHeader."Holding Order" = FALSE) AND (SalesHeader."Hold Code" <> 'HELD') THEN BEGIN //Do your stuff here END;
0 -
Sorry - forgot to reply to this, but thank you, that enabled me to do what I needed0
-
Oh don't worry about it, you're so welcome. Glad you could make it work, and thanks for following up0
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