Adding values to a multi-select field with deluge
Because subforms will only create new rows, I'm using deluge to recall information from a form into the subrows to mimic the behaviour of updating a row rather than creating it.
I have a multi select field called "locations" that is a list of locations for the client, and for every one they choose the subrow is populated with the existing data about that location from a form called "location" (confusing I know). When the form is saved it pushes any updates to that original form and all is well.
When the client edits the form I need a way to rebuild that subform data and the choices in the multi select. However I'm having trouble pushing the results to the multiselect field.
I hope this helps :
- // Get all the choices that were made for this record
- varFetchChoices = benchmarks [ ID == input.ID ].locations.getAll();
- //Clear existing subrows and choices
- clear locations;
- input.SUB_LOCATIONS.clear();
- //Rebuild the multiselect by looking up each location
- varFetch =benchmarks [ ID == input.ID ].locations.getAll();
- for each varRow in varFetch
- {
- input.locations = varRow;
- }
When I set up an alert on varRow, it displays the ID of each of the locations separately as I would expect, but it only ever inputs the one location.
I suspect it's because I need to add the varRow to a list and then insert that into the multi select - but I can't get the phrasing quite right
This is what I need the end result to look like (with varying numbers of sites)
And this is the code I am using to bring the data into the subform when a multiselect choice is made
- //Count Subform Rows
- varRowCount = 0;
- for each row in SUB_LOCATIONS
- {
- if(row.ID != 0)
- {
- varRowCount = varRowCount + 1;
- }
- }
- // Collect all the locations that are associated with this client and add to a collection
- if(location[ID = input.locations].ID != null)
- {
- //create and clear the list
- varCollection = Collection();
- varCollection.clear();
- //Add 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;
- //Returns the ID of the last in the list
- varLastLocation = varCollection.get(varLocationCount);
- //Fetch the location about the chosen location
- varFetchLocation = location[ID == varLastLocation];
- //
- // Now let's populate the subform
- for each varLocation in varFetchLocation
- {
- //create the "varNewRow" variable for holding the new row data
- varNewRow = Build_your_benchmark.SUB_LOCATIONS();
- //
- //Set the values for each row to the varNewRow variable
- varNewRow.location_name=varFetchLocation.location_name;
- varNewRow.benchmark_sector=varFetchLocation.benchmark_sector;
- varNewRow.region=varFetchLocation.region;
- varNewRow.occupants=varFetchLocation.occupants;
- varNewRow.floor_area=varFetchLocation.floor_area;
- //
- //Insert "varNewRow" to new row on the subform
- input.SUB_LOCATIONS.insert(varNewRow);
- }
- }
I hope that makes sense