How to Calculate in Nav ?

Rana
Member Posts: 123
Dear all,
I have created a Table, say Packing Lines. Primary keys are :- "Document Type","Sales Doc. No.","Sales Doc. Line No.",Item,"Line No.".
There is a "Quantity" field in this Table. I want to sum up this field's value at time of entring value. So I have written a Function Say CheckSaleInvoiceLineQty and call this function in the Quantity - OnValidate()
When I am entering any value in the quantity field the function is executed and enter into the REPEAT
UNTIL Loop , but finds PackingLines.Quantity =0 value. why ?
:shock: :shock: :shock:
I have created a Table, say Packing Lines. Primary keys are :- "Document Type","Sales Doc. No.","Sales Doc. Line No.",Item,"Line No.".
There is a "Quantity" field in this Table. I want to sum up this field's value at time of entring value. So I have written a Function Say CheckSaleInvoiceLineQty and call this function in the Quantity - OnValidate()
CheckSaleInvoiceLineQty() TotQty :=0; PackingLines.SETCURRENTKEY("Document Type","Sales Doc. No.","Sales Doc. Line No.",Item,"Line No."); PackingLines.SETRANGE("Document Type","Document Type"); PackingLines.SETRANGE("Sales Doc. No.","Sales Doc. No."); PackingLines.SETRANGE("Sales Doc. Line No.","Sales Doc. Line No."); IF PackingLines.FINDSET THEN REPEAT TotQty+= PackingLines.Quantity ; UNTIL PackingLines.NEXT = 0;
When I am entering any value in the quantity field the function is executed and enter into the REPEAT
UNTIL Loop , but finds PackingLines.Quantity =0 value. why ?
:shock: :shock: :shock:
0
Comments
-
Try: packinglines.modify;0
-
from which object and in which trigger this function is run?
CheckSaleInvoiceLineQty()
you're reading a record variable, it means that if ther record is not committed to the database, you won't see it in an instance of your table.0 -
If you are calling it from OnValidate of new line, you will not see this line in the loop, because it was not inserted yet. You need to add the actual value from Rec and subtract the old value from xRec to have correct value.0
-
kine wrote:If you are calling it from OnValidate of new line, you will not see this line in the loop, because it was not inserted yet. You need to add the actual value from Rec and subtract the old value from xRec to have correct value.
This is not working correctly! :shock: :shock: :shock:
Try this code ....TotQty :=0; PackingLines.SETCURRENTKEY("Document Type","Sales Doc. No.","Sales Doc. Line No.",Item,"Line No."); PackingLines.SETRANGE("Document Type","Document Type",); PackingLines.SETRANGE("Sales Doc. No.","Sales Doc. No."); PackingLines.SETRANGE("Sales Doc. Line No.","Sales Doc. Line No."); PackingLines.SETFILTER("Line No.",'<>%1',"Line No"); IF PackingLines.FINDSET THEN BEGIN REPEAT TotQty+= PackingLines.Quantity; UNTIL PackingLines.NEXT =0; TotQty += Qty; END;
Now or Never0 -
Use a flow field.David Singleton0
-
navuser1 wrote:kine wrote:If you are calling it from OnValidate of new line, you will not see this line in the loop, because it was not inserted yet. You need to add the actual value from Rec and subtract the old value from xRec to have correct value.
This is not working correctly! :shock: :shock: :shock:
Try this code ....TotQty :=0; PackingLines.SETCURRENTKEY("Document Type","Sales Doc. No.","Sales Doc. Line No.",Item,"Line No."); PackingLines.SETRANGE("Document Type","Document Type",); PackingLines.SETRANGE("Sales Doc. No.","Sales Doc. No."); PackingLines.SETRANGE("Sales Doc. Line No.","Sales Doc. Line No."); PackingLines.SETFILTER("Line No.",'<>%1',"Line No"); IF PackingLines.FINDSET THEN BEGIN REPEAT TotQty+= PackingLines.Quantity; UNTIL PackingLines.NEXT =0; TotQty += Qty; END;
What is Qty? I assume that you need to add Rec.Quantity and not Qty...0 -
If you are modifying the record, you need to subtract xRec.Quantity and add Rec.Quantity, if you are inserting record, you need only add the Rec.Quantity.
Could you describe some example of data an the result?0 -
kine wrote:If you are modifying the record, you need to subtract xRec.Quantity and add Rec.Quantity, if you are inserting record, you need only add the Rec.Quantity.
Could you describe some example of data an the result?
I'm creating the Packing List lines against a Sales Invoice Line. And try to block that The Packing Lines total quantity could not exceed the Sales Line Quantity0 -
I know, I though that you write which data you have in the table, which result you got, what you want to have as result ... example with data and what is wrong ("I have these records.... and when I enter XXX into new line, the sum is AAA but it should be BBB")0
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