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.
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.
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.
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...
PostCode points at the record variable
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":
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.
are 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 correct Reinhard. It is difficult because there's something called PostCode (no space, no "") and he is working in the "Post Code" table (spaces and ""). The first one points to the record variable called PostCode, and the second points back at the table he is working in.
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.
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.
Answers
RIS Plus, LLC
thanks for prompt answer.
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.
Alright, assuming you're still with me... let's take the second lline apart:
RIS Plus, LLC
Do not forget that there is implicit "WITH Rec do" in all objects...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
is a shorter way of doing:
because like Denster says
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:
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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": 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.
RIS Plus, LLC
Maybe a more user friendly example would be: You use a field value of TheOtherPostCode to set a filter on PostCodeOne.
RIS Plus, LLC
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.
you said And that is simply not correct.
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.
RIS Plus, LLC
Open NAV, click Help -> C/SIDE reference guide, and search for SETRANGE, that explains it all.
RIS Plus, LLC
RIS Plus, LLC