I am trying to add some shipping functionality to our system. In order to rate and ship packages our 3rd party software requires a sequential "box number" field for each detail record. This field *must* be a sequential number starting at 1 within each shipment.
So I've designed a header/table structure and a form to display and allow editing of the data. My detail table contains the box by box details for the shipment. The key structure is shipment number, line number, box number. The problem I'm having is keeping the boxes in sequential order while allowing the users to modify, insert, delete, etc. The table will automatically re-sort after each new record is inserted but I also need to renumber the "box number" field so that (a.) the box numbers remain sequential, and (b.) the user doesn't have to worry about where in the sequence this new record will fall. (I don't want the user to have to worry about the box number when updating or adding line items.)
The idea was to select all the lines in the shipment after a new box has been inserted and then simply re-number all the lines according to the primary key sort sequence. How should I go about this? I can't seem to find an after insert trigger which fires after the new detail line has been inserted. Would it be on my subform or my table? Is there an easier way to maintain the sequence?
Thanks,
Phil
0
Comments
2) Do not forget that when firing these triggers, the record is not inserted yet, or deleted yet. It means you need to work with this
3) After that you need only go through the records and assign numbers
(if deleting line, filter the line out when assigning the numbers, if inserting, reserve the number for your inserted line based on LineNo of your newly inserted record)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
It would be much simpler to re-sequence the table after the pending updates are complete.
Must the Box # be assigned so early in this process?
How about assigning them at the end once the entire shipment is ready to go?
Is there a reason this can't happen?
http://www.BiloBeauty.com
http://www.autismspeaks.org
I could in theory assign the box numbers at any point before I passed the data to the 3rd party routines.
What if I were to change the Box No field to be a FlowField. Could I somehow define a calc formula so that the field value would indicate the record position within the sort order? If that works would I still be able to use the field as part of the record key?
I'm not sure how you export the data - but my thought was either a function that adds box numbers once the shipment is complete or on export (say using a dataport) if that's what you use. As each box gets exported
Box := Box +1;
Also by using the box as the key & losing the line no - your boxes should sort in order.
Another thought is if you had a total box count you could then see if the last box equals that total box # else there's a missing sequential box #... Count is an option for a flowfield.
http://www.BiloBeauty.com
http://www.autismspeaks.org
I believe I'll try it just as you suggest. I already have the FlowField setup on the header record to give me a "box count".
So again I'm in need of an AFTER delete trigger, or a delete trigger which is only called one time rather than once for each record.
This is how I was going about the delete process. Selecting all the box records, renaming them to a new range, and then renaming them back to a sequential order less the record to be deleted. The below code works fine if the user is only attempting to delete 1 box at a time.
So the questions are:
1.) How can I change the code to allow the user to delete multiple boxes at the same time?
2.) How can I suppress the "Are you sure you want to rename this record?" prompt?
HOWEVER, some strange issues still persist.
If I select rows 1, 2, and 3 and then delete them. The system deletes rows 1, 3, and 5.
If I select rows 1, 3, and 5 and then delete them. The system deletes rows 1, 4, and 7.
LOL, what is going on here?!
Its almost as if the selection isn't changing as the rows get removed. So as row 1 is removed and row 2 takes its place the selection doesn't change, even though the data in that row has changed.
Here is the code:
2) In the loops, you are renaming the records, but you are iterating through them. Ok, it should not change the order, but it is not good in general. At least, use the FINDSET(True,True) to do it nicely and never use the FINDFIRST when using repeat until after it!
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!