Subform : Recall existing data into subform - not create new data
My use case is that I have a multi-select field where I want users to be able to choose locations that already exist and bring them into a subform to edit. The subform is linked - not an inline one. The multi-select field and the subform are the "locations" form.
I need to be able to fetch and update existing records, not create new ones
I can get the first part of the code to return the record for the last
option chosen in the multi-select. I just need it to populate (and
thereby link) the existing location record.
- //Use a null check to stop it running if there is nothing to match
- if(location[ID = input.locations].ID != null)
- {
- varLocations = input.locations;
- //create and clear the list as it's run every time something is added to the multiselect
- varCollection = Collection();
- varCollection.clear();
- //Add all the selected locations to the collection
- varCollection.insertall(input.locations);
- //Get the size of the collection (minus a one because it's a zero index)
- varLocationCount = varCollection.size() - 1;
- //Now we just need the ID of the last location chosen
- varLastLocation = varCollection.get(varLocationCount);
- //
- //Fetch the location about the chosen location
- varFetchLocation = location[ID == varLastLocation];
- //
- // Here's where I try to add the fetched location to the subform
- for each row in input.SUB_LOCATIONS
- {
- row.ID = varFetchLocation.ID;
- row.location_name = varFetchLocation.location_name;
- }
- }
Here's a visual example of my desired end result
