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?
0
Comments
Since you are in a report you could do the following:
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.
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.
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.
In such a scenario you could:
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?
Thank you for the help, will give your suggestion a go!
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!