Select order header record
imurphy
Member Posts: 308
What am I doing wrong? The following code comes from a button I have placed on the Sales Orders form:
It should 'load' the Sales Order Header for the currently visible record on the form into OrderHeader ... no?
The same code works fine for selecting sales order lines.
What am I doing wrong?
-- Ian
OrderHeader.RESET;
OrderHeader.SETRANGE("Document Type","Document Type");
OrderHeader.SETRANGE("No.","No.");
IF (OrderHeader.COUNT = 0) THEN
MESSAGE ('No header record found');
It should 'load' the Sales Order Header for the currently visible record on the form into OrderHeader ... no?
The same code works fine for selecting sales order lines.
What am I doing wrong?
-- Ian
0
Comments
-
The OrderHeader.COUNT just COUNTS the number of records. It does NOT get a record in the buffer.
To get the record, you better do this:
IF NOT OrderHeader.GET("Document Type",No.") THEN
MESSAGE ('No header record found');
Or if you also need the filters:
OrderHeader.RESET;
OrderHeader.SETRANGE("Document Type","Document Type");
OrderHeader.SETRANGE("No.","No.");
IF NOT OrderHeader.FINDFIRST THEN // or FIND('-') in pre 4.0SP1 versions
MESSAGE ('No header record found');Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I'd guess that SETFILTER or .NEXT have a sideeffect which does the same. This is some code which is working for Sales Lines:
SalesLine.RESET; SalesLine.SETRANGE("Document Type","Document Type"); SalesLine.SETRANGE("Document No.","No."); SalesLine.SETFILTER(Quantity,'<>0'); IF (SalesLine.NEXT <> 0) THEN REPEAT ..... UNTIL (SalesLine.NEXT = 0);
Thanks for the pointer.
Ian0 -
To do some looping, you should use this:
SalesLine.RESET; SalesLine.SETRANGE("Document Type","Document Type"); SalesLine.SETRANGE("Document No.","No."); SalesLine.SETFILTER(Quantity,'<>0'); IF SalesLine.FINDSET THEN // or FIND('-') but not FINDFIRST REPEAT ..... UNTIL (SalesLine.NEXT = 0);If you use a NEXT to find the first record, you can't be sure of the result.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
imurphy wrote:What am I doing wrong? The following code comes from a button I have placed on the Sales Orders form:OrderHeader.RESET;
OrderHeader.SETRANGE("Document Type","Document Type");
OrderHeader.SETRANGE("No.","No.");
IF (OrderHeader.COUNT = 0) THEN
MESSAGE ('No header record found');
It should 'load' the Sales Order Header for the currently visible record on the form into OrderHeader ... no?
The same code works fine for selecting sales order lines.
What am I doing wrong?
-- Ian
Since you already have the record, why retrieve it again?
OrderHeader := Rec;There are no bugs - only undocumented features.0 -
Now thats a well hidden little piece of info. Haven't noticed it being used in any of the internal forms I've been browsing through, they all seem to do something similar to what I've been doing.
Thanks for that - should save me a load of time.
Ian0 -
Hey - just an FYI - you do not have to tell the form to go get anything from the database, it does that already, that is why you don't see normal forms putting any code in them to retreive database records.
If you create a blank form based on the customer table, with just the no field on it, and scroll through the records, you'll see them flash through without the addition of any code.
-a0 -
By well hidden, I meant that searching the docs I can't find a single reference to the fact that rec is always assigned to the primary record on a card.
CurrForm is the current form, so logically CurrRec or CurrRecord would be the current record and not rec.
Searching for either of these shows up nothing and trawling through the code in various forms also doesn't show up much - though I'm sure it is used in some places.
Ian0 -
Well on a report there is CurrReport. but that refers to the report, not the record.
You do not see it much because the scope of Rec means that you rarely need to actually type 'Rec'.
On a sales order form, you do not need to type:
Rec."No."
just
"No."
Same thing in the sales order table, you can omit the Rec prefix.
The place you do see Rec is when you press F5 and get the variable window up, then you can browse Rec for fields, functions, etc...
-a0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions