Which object type are you working on? Are you trying to apply these filter to a report, form, page, codeunit or in SQL?
And always remember to say version your question is about. [:)]
So you are doing this in the code of table 113? On which trigger? On insert or modify?
Table 113 are posted invoice lines and normally you are not allowed to change those. Neither is it very good practice to add additional functions here. You should rather put new code like this in a separate codeunit, as that will make future upgrades much easier.
It would help to know the content of your question. What is the purpose of doing this?
Also as far as I can see on your question, then you talk about filters, but your example is not about filters, but about finding the most common unit of measure or something.
And in a rather complex way, that is not easy to do in standard NAV code. I’m not a SQL Query expert, but from what I can see, then it’s maybe better to use queries. But since you still haven’t told us, which version your question is about, then I don’t know if you have that option.
the purpose is all about practicing using simple Filter functions.
i wrote my code in a separate Report as i know that i am not allowed to make changes on table 113.
i have made a new Function that will take as a parameter a Posted Sales Invoice No. which is ‘Document No.’ on table 113.
i need to write code inside that function that finds that specific Posted Sales Invoice and
then find the “Unit of Measure Code” that exists the most times in the first 3 Posted Sales Invoice lines (regarding Line No.) that have Type = Item.
my code should take care of the following cases:
-If there is no lines of ‘Type = Item’ exists, it will return blank.
-If there is less than 3 lines of ‘Type = Item’ exists, it will return the “Unit of
Measure Code” that exists the most times between the Items.
-If they are 3 Items or only 2 Items, and each of them has a different “Unit of Measure
Code”, return the “Unit of Measure Code” of the first Item in order of the ‘Line No.’
So you didn’t write your code in table 113 as you wrote above?? Ok, that makes a bit more sense. But would have helped to know that you’re trying to make a report, which displays this information.
The only filter you are going to set here is SETRANGE(Type,Type::Item); - otherwise no filters here. But you are going to need to do a lot of code in NAV to get there. My guess it would take me an hour or two to get it right. I also think that this could be done smarter using Queries.
As You Were Trying in Report take a Local Record Variable in OnpreReport And Setfilter For Particular Document No
then Findset and Save the Diff types of UOM Codes into a Array OF Code Global Variable
So Now You Have all Diff UOM Codes
Now Take Same Array length Of Integer Global Variable
In Dataitem OnAfter Get record Compare Like Below
For i := 0 To ARRAYLEN(ArrayCode) Do Begin
If ArrayCode[i] = Sales Invoice Line.Unit of Measure Code THEN
ArrayInt[i] := ArrayInt[i] +1;
End;
[mention:a5a4ef108ad74213860dab349c8c4db9:e9ed411860ed4f2ba0265705b8793d05] : if you don’t the [i] - then use the “Insert Code” function of the rich editor. That’s much better to format source code (although no highlighting of NAV syntax yet).
Thank you very much Raja. It’s good to hear that you like it. [:)]
And if “someone” had the time, they could create “plug-in” for the code viewer, which would highlight the Navision syntax, just as it works if you use C# code…
Code3L := SalesInvLineL.“Unit of Measure Code”;
UNTIL (SalesInvLineL.NEXT = 0) OR (Count = 3);
END;
in above code All three variables are getting same UOMcode.
So u might have to give some contidition like
if count = 1 then
Code1L = SalesInvLineL.“Unit of Measure Code”;
if count = 2 then
Code2L := SalesInvLineL.“Unit of Measure Code”;