Can someone enlighten me on this code...

NavNab
Member Posts: 181
Dear all,
Can someone enlighten me to understand this code in standard report 295. The screenshot is from a NAV 2017 W1 database, but the code exists in all (2009 at least) old versions also.

I can't see what is the purpose of assigning a value to a field just after/before a SETRANGE.
The same logic is used on other standard objects. For example Table 175, function ApplyStdCodesToPurchaseLines
Can someone enlighten me to understand this code in standard report 295. The screenshot is from a NAV 2017 W1 database, but the code exists in all (2009 at least) old versions also.

I can't see what is the purpose of assigning a value to a field just after/before a SETRANGE.
The same logic is used on other standard objects. For example Table 175, function ApplyStdCodesToPurchaseLines
0
Best Answers
-
Hi,
You would need to have a look in the code down below ans see how the assigned data is used. 4 lines of code taken out of context almost never makes sense.
It could be used just to remember values of Document No. / Type to be used somewhere else. SETRANGE will only set the filter, without putting a value in the actual fields, so if you had used SETRANGE only and later want to have the "Document Type" assigned somewhere later you in the code would have to use IF EVALUATE(GETFILTER("DocumentType")) rather that straightforward assignment.
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
This is done to set filters and values to the object SalesLine.
There is no FIND after the SETRANGE so the filer is not executed.
This object is passed in the next statements:HasAmount := HasAmount OR ("Qty. Shipped Not Invoiced" <> 0); SalesShptLine.InsertInvLineFromShptLine(SalesLine);
The SETRANGE is used to determine the next lineno.
(IF SalesLine.FIND('+') THEN)
And to set the values:
SalesLine."Document Type" := TempSalesLine."Document Type";
SalesLine."Document No." := TempSalesLine."Document No.";InsertInvLineFromShptLine(VAR SalesLine : Record "Sales Line") SETRANGE("Document No.","Document No."); TempSalesLine := SalesLine; IF SalesLine.FIND('+') THEN NextLineNo := SalesLine."Line No." + 10000 ELSE NextLineNo := 10000; IF SalesInvHeader."No." <> TempSalesLine."Document No." THEN SalesInvHeader.GET(TempSalesLine."Document Type",TempSalesLine."Document No."); IF SalesLine."Shipment No." <> "Document No." THEN BEGIN SalesLine.INIT; SalesLine."Line No." := NextLineNo; SalesLine."Document Type" := TempSalesLine."Document Type"; SalesLine."Document No." := TempSalesLine."Document No."; SalesLine.Description := STRSUBSTNO(Text000,"Document No."); SalesLine.INSERT; NextLineNo := NextLineNo + 10000; END;
5
Answers
-
Hi,
You would need to have a look in the code down below ans see how the assigned data is used. 4 lines of code taken out of context almost never makes sense.
It could be used just to remember values of Document No. / Type to be used somewhere else. SETRANGE will only set the filter, without putting a value in the actual fields, so if you had used SETRANGE only and later want to have the "Document Type" assigned somewhere later you in the code would have to use IF EVALUATE(GETFILTER("DocumentType")) rather that straightforward assignment.
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
This is done to set filters and values to the object SalesLine.
There is no FIND after the SETRANGE so the filer is not executed.
This object is passed in the next statements:HasAmount := HasAmount OR ("Qty. Shipped Not Invoiced" <> 0); SalesShptLine.InsertInvLineFromShptLine(SalesLine);
The SETRANGE is used to determine the next lineno.
(IF SalesLine.FIND('+') THEN)
And to set the values:
SalesLine."Document Type" := TempSalesLine."Document Type";
SalesLine."Document No." := TempSalesLine."Document No.";InsertInvLineFromShptLine(VAR SalesLine : Record "Sales Line") SETRANGE("Document No.","Document No."); TempSalesLine := SalesLine; IF SalesLine.FIND('+') THEN NextLineNo := SalesLine."Line No." + 10000 ELSE NextLineNo := 10000; IF SalesInvHeader."No." <> TempSalesLine."Document No." THEN SalesInvHeader.GET(TempSalesLine."Document Type",TempSalesLine."Document No."); IF SalesLine."Shipment No." <> "Document No." THEN BEGIN SalesLine.INIT; SalesLine."Line No." := NextLineNo; SalesLine."Document Type" := TempSalesLine."Document Type"; SalesLine."Document No." := TempSalesLine."Document No."; SalesLine.Description := STRSUBSTNO(Text000,"Document No."); SalesLine.INSERT; NextLineNo := NextLineNo + 10000; END;
5 -
Thanks both of you. Now I see clear.
Although it isSlawek_Guzek wrote: »straightforward assignment
It is still a disturbing manner to code. It would be simple and easy to understand if the code was:... InsertInvLineFromShptLine(VAR SalesLine : Record "Sales Line",SalesHeader); ... SalesLine."Document Type" := SalesHeader."Document Type"; SalesLine."Document No." := SalesHeader."No."; ...
The way @ErictP explains it sounds like a nice trick: SETRANGE to FIND next Line No. and := for assigning values... but still disturbing
Anyway, it is a way of coding as another...0 -
You will get used to it
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030
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