Filters

hallo everyone,
please which and how can i set a filter to find the ‘Unit of Measure Code’(Field) that

exists the most times in the first 3 Posted Sales Invoice Lines (regarding ‘Line No.’

Field) that have Type = Item.

-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.’

thank you very much

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. [:)]

sorry i thought it was clear enough :slight_smile:

i m working on table ‘Sales Invoice Lines’ and i want to set my filters on this table.

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. :slight_smile:

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.

Hi AMoussaoui,

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).

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;

Thanks Erik P. Ernst . i haven’t seen it Really Good to Know. New Dug Is Awesome…[H]

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…

Hi There,

I Do got a Solution Directly But there are some Limitations

  1. You have to know Maximum no of Lines may be defined in Sales Order So that you can define in Array(i.e Dimensions).

  2. Maybe you should How many Types of UOM Code so that it Simplifies the Code to Large Extent As first we have to Search for all UOM types

3.I’m Not a NAV Expert So there might be Other ways to do that keep trying for the Best Code…

Lastly This is Code I wrote Works Fine For up to 10 Sales Lines…

OnInitReport()

OnPreReport()
i:=1;
SalesInvoiceLineG.RESET;
SalesInvoiceLineG.SETRANGE(SalesInvoiceLineG."Document No.",DocumentNo);
IF SalesInvoiceLineG.FINDSET THEN BEGIN
  REPEAT
   // MESSAGE('%1',SalesInvoiceLineG."Unit of Measure Code");
    ArrayCode[i] := SalesInvoiceLineG."Unit of Measure Code";
    i := i+1;
    UNTIL SalesInvoiceLineG.NEXT =0;
    END;

OnPostReport()

Sales Invoice Line - OnPreDataItem()
"Sales Invoice Line".SETRANGE("Sales Invoice Line"."Document No.",DocumentNo);

Sales Invoice Line - OnAfterGetRecord()

CASE "Sales Invoice Line"."Unit of Measure Code" OF 
ArrayCode[1] : 
BEGIN
ArrayInt[1] := ArrayInt[1] +1;
END;
ArrayCode[2] : 
BEGIN
ArrayInt[2] := ArrayInt[2] +1;
END;
ArrayCode[3] : 
BEGIN
ArrayInt[3] := ArrayInt[3] +1;
END;
ArrayCode[4] : 
BEGIN
ArrayInt[4] := ArrayInt[4] +1;
END;
ArrayCode[5] : 
BEGIN
ArrayInt[5] := ArrayInt[5] +1;
END;
ArrayCode[6] : 
BEGIN
ArrayInt[6] := ArrayInt[6] +1;
END;
END;
//Hashxd.h

Sales Invoice Line - OnPostDataItem()
FOR i:= 1 TO 10 DO BEGIN
  IF ArrayInt[i] > HighCount THEN
    HighCount := i;
  
  END;
  MESSAGE('%1 %2',ArrayCode[HighCount],HighCount);

Select ArrayCOde and Set Dimensions of no no of Lines as I took 10

dimensions.png

hi Raja,

thank you very much :slight_smile:

i will check if its helpful.

this is my last version of code that i taped.

LOCAL FunctionInvLine(pDocumentNo : Code[20]) RUnitOfMeasure : Code[10]

SalesInvLineL.RESET;

SalesInvLineL.SETCURRENTKEY(“Document No.”,“Line No.”);

//Document No.

SalesInvLineL.SETRANGE(SalesInvLineL.“Document No.”, pDocumentNo); //gd

SalesInvLineL.SETRANGE(SalesInvLineL.Type,SalesInvLineL.Type::Item); //gd

Count := 0;

CLEAR(ArrayTextL);

Code1L := ‘’;

Code2L := ‘’;

Code3L := ‘’;

IF SalesInvLineL.FINDSET THEN BEGIN

REPEAT

Count := Count + 1;

Code1L := SalesInvLineL.“Unit of Measure Code”;

Code2L := SalesInvLineL.“Unit of Measure Code”;

Code3L := SalesInvLineL.“Unit of Measure Code”;

MESSAGE(Code1L);

MESSAGE(Code2L);

MESSAGE(Code3L);

UNTIL (SalesInvLineL.NEXT = 0) OR (Count = 3);

END ELSE BEGIN

RUnitOfMeasure := ‘’;

END;

3107.Capture.PNG

Capture1.PNG

Capture2.PNG

please feel free to comment :slight_smile:

IF SalesInvLineL.FINDSET THEN BEGIN

REPEAT

Count := Count + 1;

Code1L := SalesInvLineL.“Unit of Measure Code”;

Code2L := SalesInvLineL.“Unit of Measure 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”;