Explaining Setrange

Jambo
Member Posts: 12
Hi,
can somebody explain me what the following code line means:
While the meaning of the first "No." is clear to me,
the second one is confusing me. The second one should be
a value or not?
can somebody explain me what the following code line means:
SalesOrderLine.SETRANGE("No.","No.");
While the meaning of the first "No." is clear to me,
the second one is confusing me. The second one should be
a value or not?
0
Answers
-
That is a way of linking one record variable to another one. The second "No." refers to the "No." field of that other variable. It is probably part of a WITH block, or part of some dataitem code, or in code the "No." field got set and then it wants to filter on that value.0
-
Daniel,
thanks for prompt answer.It is probably part of a WITH block, or part of some dataitem code, or in code the "No." field got set and then it wants to filter on that value.
I have found this type of code mostly in OnValidate triggers in serveral
Tables. There are no WITH block or dataitem nor "No." got set in code.
You can view it for example in Table Post Code (225) in OnValidate
trigger. Let me know your opinion.0 -
OK, so taking that table as an example. In the Code - OnValidate trigger it says this:
PostCode.SETCURRENTKEY("Search City"); PostCode.SETRANGE("Search City","Search City"); PostCode.SETRANGE(Code,Code); IF PostCode.FIND('-') THEN ERROR(Text000,FIELDCAPTION(Code),Code);
Now remember we are in the "Post Code" table, so every field reference is to the table itself. this means when you see "Search City" without a record variable reference, that means it is referring to the table's field value.
Alright, assuming you're still with me... let's take the second lline apart:PostCode.SETRANGE("Search City","Search City");
- PostCode.SETRANGE means we are going to set a range filter on the PostCode variable, which is a record type variable pointing to the Post Code table.
- PostCode.SETRANGE("Search City" means we are going to apply the filter to the "Search City" field of the PostCode variable
- The second "Search City" specifies the value of the filter, and refers to the "Search City" field of the current Post Code record.
0 -
Jambo wrote:Daniel,
thanks for prompt answer.It is probably part of a WITH block, or part of some dataitem code, or in code the "No." field got set and then it wants to filter on that value.
I have found this type of code mostly in OnValidate triggers in serveral
Tables. There are no WITH block or dataitem nor "No." got set in code.
You can view it for example in Table Post Code (225) in OnValidate
trigger. Let me know your opinion.
Do not forget that there is implicit "WITH Rec do" in all objects...0 -
PostCode.SETRANGE("Search City","Search City"); PostCode.SETRANGE(Code,Code);
is a shorter way of doing:PostCode.SETRANGE("Search City",PostCode."Search City"); PostCode.SETRANGE(Code,PostCode.Code);
because like Denster saysare in the "Post Code" table, so every field reference is to the table itself
Specifically in this situation you are filtering the entire record set PostCode on a field by the value in the current record.0 -
Reinhard wrote:
PostCode.SETRANGE("Search City","Search City"); PostCode.SETRANGE(Code,Code);
is a shorter way of doing:PostCode.SETRANGE("Search City",PostCode."Search City"); PostCode.SETRANGE(Code,PostCode.Code);
because like Denster saysare in the "Post Code" table, so every field reference is to the table itself
Specifically in this situation you are filtering the entire record set PostCode on a field by the value in the current record.
This is not true until there is somewhere With PostCode Do...
Else it is in real:PostCode.SETRANGE("Search City",Rec."Search City"); PostCode.SETRANGE(Code,Rec.Code);
0 -
kine wrote:Else it is in real:
PostCode.SETRANGE("Search City",Rec."Search City"); PostCode.SETRANGE(Code,Rec.Code);
Rec points back at the table you are in. This is left out in the first example.
Another possibility is when you are in a report dataitem for the Post Code table, called "Post Code":PostCode.SETRANGE("Search City","Post Code"."Search City"); PostCode.SETRANGE(Code,"Post Code".Code);
Note the difference between PostCode (no space, no "") and "Post Code" ("" and space):
PostCode points at the PostCode variable
"Post Code" points back at the dataitem.0 -
Reinhard wrote:
PostCode.SETRANGE("Search City","Search City"); PostCode.SETRANGE(Code,Code);
is a shorter way of doing:PostCode.SETRANGE("Search City",PostCode."Search City"); PostCode.SETRANGE(Code,PostCode.Code);
because like Denster saysare in the "Post Code" table, so every field reference is to the table itself
Specifically in this situation you are filtering the entire record set PostCode on a field by the value in the current record.
Maybe a more user friendly example would be:PostCodeOne.SETRANGE("Search City",TheOtherPostCode."Search City"); PostCodeOne.SETRANGE(Code,TheOtherPostCode.Code);
You use a field value of TheOtherPostCode to set a filter on PostCodeOne.0 -
Denster,
yes that's true but also not entirely necessary. PostCodeOne could potentially equal TheOtherPostCode and you would still see the "confusing"
SETRANGE("No.","No.") syntax... so its not that PostCode <> "Post Code" that I think is confusing, but that strangely: "No." is not the same as "No."!
The first "No." is the name of a field, the second one is a pointer to a specific value.0 -
@ Reinhard:
you saidReinhard wrote:PostCode.SETRANGE("Search City","Search City"); PostCode.SETRANGE(Code,Code);
is a shorter way of doing:PostCode.SETRANGE("Search City",PostCode."Search City"); PostCode.SETRANGE(Code,PostCode.Code);
The second SETRANGE parameter refers either to Rec, or to the dataitem you are in. It never refers back to PostCode, unless you are in a dataitem that you called PostCode.0 -
@ Jambo:
Open NAV, click Help -> C/SIDE reference guide, and search for SETRANGE, that explains it all.0 -
no problem, it's easy to mix this type of stuff up, I had to look at it more than once to make sure I was looking at it right0
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