Update only one sales line per Trip

Gary_J
Member Posts: 12
Hi,
"Trip" is a custom field linked to a new table, it basically identifies the lorry a sales line is being shipped on. Each sales order can have different Trips against each line, eg:
10000 / Item 1 / Trip 5000A
20000 / Item 2 / Trip 5000A
30000 / Item 3 / Trip 6030B
etc.
I need to find a way to loop through the sales lines and pull a value from the Trips table and assign it to the first line using that trip. So:
10000 / Item 1 / Trip 5000A - assign the value
20000 / Item 2 / Trip 5000A - don't assign the value
30000 / Item 3 / Trip 6030B - assign the value
I've created a processing-only report which does the loop and assigns the value, but at the moment it assigns the value to all the sales lines. This is the code in OnAfterGetRecord:
IF trip.GET("Sales Line".TripNo) THEN
"Haulage Cost" := trip."Haulage Cost";
Can anyone help?
"Trip" is a custom field linked to a new table, it basically identifies the lorry a sales line is being shipped on. Each sales order can have different Trips against each line, eg:
10000 / Item 1 / Trip 5000A
20000 / Item 2 / Trip 5000A
30000 / Item 3 / Trip 6030B
etc.
I need to find a way to loop through the sales lines and pull a value from the Trips table and assign it to the first line using that trip. So:
10000 / Item 1 / Trip 5000A - assign the value
20000 / Item 2 / Trip 5000A - don't assign the value
30000 / Item 3 / Trip 6030B - assign the value
I've created a processing-only report which does the loop and assigns the value, but at the moment it assigns the value to all the sales lines. This is the code in OnAfterGetRecord:
IF trip.GET("Sales Line".TripNo) THEN
"Haulage Cost" := trip."Haulage Cost";
Can anyone help?
0
Comments
-
Gary_J wrote:IF trip.GET("Sales Line".TripNo) THEN
"Haulage Cost" := trip."Haulage Cost";
Since you are in a report you could do the following:IF BoolLineModified THEN CurrReport.SKIP; IF trip.GET("Sales Line".TripNo) THEN BEGIN "Haulage Cost" := trip."Haulage Cost"; BoolLineModified := TRUE; END;
You will need a condition to set BoolLineModified to false maybe in a Sales Header DataItem
Practically there are tons of ways to achieve what you want.0 -
Hi, thank you for the advice.
I have tried what you suggested and while it works fine if there is only one trip no on the sales lines, it does not work if there are multiple trip numbers (like my example). I put BoolLineModified := false in the OnPreDataItem section, is that the right place? Also, the report only runs on the Sales Lines.0 -
Can you post your code here along with the dataitems setup?0
-
Documentation() OnPreDataItem() "Sales Line".SETRANGE("Document Type", "Document Type"::Order); "Sales Line".SETRANGE(Type, Type::Item); BoolLineModified := FALSE; iCount := 0; iTotal := "Sales Line".COUNT; dlgProgress.OPEN(CurrReport.OBJECTID(FALSE) + ' Updating Haulage Costs on Sales Lines:\' + '@1@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'); OnAfterGetRecord() IF BoolLineModified THEN CurrReport.SKIP; IF trip.GET("Sales Line".TripNo) THEN BEGIN "Haulage Cost" := trip."Haulage Cost"; BoolLineModified := TRUE; modify(true); END; iCount := iCount + 1; dlgProgress.UPDATE(1, ROUND(iCount * (10000 / iTotal), 1)); YIELD; OnPostDataItem() dlgProgress.CLOSE;
0 -
What sorting have you used for the sales line? Have you tried to debug the report to see were it exits?0
-
Sorting on the sales line is "SORTING(Document Type,Document No.,Line No.) ORDER(Ascending)".
If I use the debugger (with breakpoint on triggers), the report appears to run OK for the first trip but exits before it gets to the next one. I think it keeps looping through the same section (for one trip) because BoolLineModified is always TRUE, and because it can't detect the change in Trip number the report finishes.0 -
So you need to Rechange the value if the trip code changes?
In such a scenario you could:IF BoolLineModified AND( processedTripNo = TripNo) THEN CurrReport.SKIP; IF (trip.GET("Sales Line".TripNo) AND ( processedTripNo <> TripNo) THEN BEGIN "Haulage Cost" := trip."Haulage Cost"; BoolLineModified := TRUE; processedTripNo := TripNo; END;
Something like that. You could also create a temporary table variable and store in it the processed trips changing your code to something like:
IF NOT tempTripTable.GET(TripNo) THEN BEGIN
END;
Does this help?0 -
Yes, that's right about the value changing if the trip code changes.
Thank you for the help, will give your suggestion a go!0 -
Great, I think it works!
There was one small problem I found when I noticed the same trip number being used further down the sales lines, so the report was copying the value again (because the trip number had changed in between). However, I was able to change the sort sequence on the sales lines to TripNo and it appears to be working.
Thank you very much for your help!0 -
You're welcome. But you should test it extensively. Maybe changing your sorting to TripNo changes also the First Line in the recordset... Just an idea...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