Subform : Recall existing data into subform - not create new data

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.

  1. //Use a null check to stop it running if there is nothing to match
  2. if(location[ID = input.locations].ID != null)
  3. {
  4.     varLocations = input.locations;
  5.     //create and clear the list as it's run every time something is added to the multiselect
  6.     varCollection = Collection();
  7.     varCollection.clear();
  8.     //Add all the selected locations to the collection
  9.     varCollection.insertall(input.locations);
  10.     //Get the size of the collection (minus a one because it's a zero index)
  11.     varLocationCount = varCollection.size() - 1;
  12.     //Now we just need the ID of the last location chosen
  13.     varLastLocation = varCollection.get(varLocationCount);
  14.    //
  15.     //Fetch the location about the chosen location
  16.     varFetchLocation = location[ID == varLastLocation];
  17.     //
  18.     // Here's where I try to add the fetched location to the subform
  19.           for each row in input.SUB_LOCATIONS
  20.           {
  21.           row.ID = varFetchLocation.ID;
  22.           row.location_name = varFetchLocation.location_name;
  23.           }
  24. }

Here's a visual example of my desired end result

    Zoho Marketing Automation
              • Sticky Posts

              • Zoho Creator Developer's Conference 2017 !!!

                We welcome all our Creator Developers! You're invited to join us for our annual Zoholics Developers conference August 29th–31st! This is your chance to get training and guidance on Zoho Creator from our most knowledgeable custom app builders.       Zoholics Developers is a three-day event where you'll participate in interactive workshops to hone your app-building skills, get questions answered by Creator experts with personal one-on-one sessions, and connect with other Creator developers from around
              • Share your success story

                We would like to hear from our passionate users how much Zoho Creator has changed the way you work and benefited you. If you would like to share your story to us and be featured as a proud user of Zoho Creator, then this is for you. Fill up the form below and if you want to be included in a case study, we will get in touch with you to get further details. So what are you waiting for? Tell us your story. Charles

              Zoho Pagesense Resources

                Zoho SalesIQ Resources



                      Zoho TeamInbox Resources

                        Zoho DataPrep Resources



                          Zoho CRM Plus Resources

                            Zoho Books Resources


                              Zoho Subscriptions Resources

                                Zoho Desk Resources

                                  Zoho Projects Resources


                                    Zoho Sprints Resources


                                      Qntrl Resources


                                        Zoho Creator Resources


                                          Zoho WorkDrive Resources




                                              Zoho Campaigns Resources

                                                Zoho CRM Resources

                                                        Design. Discuss. Deliver.

                                                        Create visually engaging stories with Zoho Show.

                                                        Get Started Now