Hi people, firstly thanks for all
this is my problem:
I need to show on Form 7012 (purchase prices) the field "line discount%" (table "Purchase Line Discounts")
I tried to do it with a function, as other times, but in this case I need to link two fields "Vendor No." and "Item No.", tables "Purchase Price" and "Purchase Line Discounts"
this is the code:
TraeDescuento() : Decimal
WITH Descuento DO BEGIN
SETRANGE("Vendor No.","Vendor No.");
SETRANGE("Item No.","Item No.");
IF FIND('-') THEN
EXIT(Descuento."Line Discount %")
END;
where:
Descuento is a variable type "Record" subtype "Purchase Line Discount"
but it does not work, it gives me no error but it does not return data
any ideas???
0
Answers
SETRANGE("Vendor No.",'');
SETRANGE("Item No.",'');
A solution is to add parameters to the fucntion like p_VendorNo (CODE 20), p_ItemNo (CODE 20) and then in the code
SETRANGE("Vendor No.",p_VendorNo);
SETRANGE("Item No.",p_ItemNo);
2. Try to check if you can use FINDFIRST instead of FIND('-');
Good Luck
KB
Depending on the records you entered in these tables and the filter you want to use, you should rather use FINDLAST.
VendNoFilter:="Vendor No.";
ItemNoFilter:="Item No.";
WITH Descuento DO BEGIN
SETRANGE("Vendor No.",VendNoFilter);
SETRANGE("Item No.",ItemNoFilter);
IF FIND('-') THEN
EXIT(Descuento."Line Discount %")
END;
Thanks for all!!
So in your example the WITH statement changed the "Vendor No." and "Item No." to be taken from the Descuento and not from the current record. Your initial code was like this for the compiler:
So you could resolve this issue by changing your code to something similar to this:
In this example I have directly told to the NAV to use values from the Rec variable. Try to always use variable names inside the code, especially if you are not sure of your code. To be honest I would advise it even if you are sure of your code. I have seen a lot of bugs done this way by developers with years of experience.
I would advice you to check how NAV debugger works. This will help you a lot to understand what is happening inside of your code.
Try to consider einsTeIn.NET advice too. Do you need the first record or maybe the last one from that table?
At the end I would advice you to have a look here: http://www.mibuso.com/howtoinfo.asp?FileID=22. This tutorial will point you to few other aspects, like missing RESET function, FINDFIRST/FINDLAST functions or SETCURRENTKEY (which is required if you work on SumIndexFields, or you don't use SQL, or if you need to get records in specific order under the SQL. If you use SQL then in case of your code you don't need to worry about it. SQL will handle ti for you).