Your case is a common scenario in Servoy. Your edit form does not share the same foundset as the source form – because it is related to whatever calendar item you’re on. The main issue being that if the destination foundset doesn’t contain the source foundset record, you will not arrive on the source record on the destination form.
There are three recommended solutions:
Solution #1: Search for the destination record
In the target form, search for the PK that you are looking for. A simple brute force approach that works every time. One potential downside is that you leave the user with no “context” – no records to browse that might be related to the destination record.
Solution #2: Go through the destination foundset until you hit the record
If you want to keep the destination form’s foundset and arrive on the correct record, you need to loop through the foundset until you hit the record you want and then stop. The loop forces Servoy to load the next 200 records when it reaches the end of the currently loaded records in the foundset.
The upside to this approach is that you retain the destination form’s foundset. The downside is that if your record happens to be at the 30,000th record slot – you’ve just brought your solution to its knees for a bit of time. For this reason, this approach is not recommended except in very specific situations.
This same warning applies to loading ALL of the destination forms records as outlined earlier in this thread! Not recommended unless you know what the implications are.
Solution #3: Load the source foundset into the destination foundset
(Harjo alluded to this solution near the top.) A typical example of going to a related record is when you are viewing a list of child records on a parent record form and you want to go to the detail form for the child record.
The trick is to assign the destination form the same foundset as the source form:
forms.destination_form_name.controller.loadRecords(source_form_name.foundset)
The advantage to this technique is that you get a set of records at your destination which provides context for the record you navigated to. However, this context is supplied by the source form, not the destination form. This can be a disadvantage depending on what you are trying to achieve. A bonus to this technique is that you don’t have to do anything to navigate to the correct index. Forms that share the same foundset also share the same record index. If you started from index 3,054 you will arrive at index 3,054.
Summary
Forms based on the same table typically share the same foundset and record index. In situations where they don’t share the same foundset, going to the same record in the destination form can be accomplished several different ways:
- find the record directly
- loop through the destination form’s foundset until you hit the record you want by PK
- assign the source form foundset to the destination form
All three techniques have their advantages and disadvantages. The first technique is fool proof but provides no context (great for edit record situations!). The last technique provides context but not necessarily the context the user is expecting. With the second technique you get the expected context but performance is a significant disadvantage.
We usually default to the last technique but it is not always a clear cut choice.
We’ve been running into this confusion with new clients and developers for so many years we wrote this all up in a tip file a long time ago!