Tip 21: How to dynamically auto-populate rows in a subform

Tip 21: How to dynamically auto-populate rows in a subform



Hi folks,

In our last tip we discussed how to autopopulate values in subform rows while clicking on Add New. As promised, in this tip, we'll show you how to dynamically insert rows in the the subform without clicking the Add New button, using our new feature—Insert rows in Subform dynamically.

Let's say you have an application where you have the product name in the Mainform field, and you need to automatically display the price of the product in the subform field based on the choice selected in Mainform field.

The Mainform contains a dropdown field named Shoes, with a list of choices like "Puma" and "Nike." The main form has a subform called SubForm containing a "Currency" field, as shown in the screenshot below.




When a product is selected from the Shoes dropdown field, the Currency field in the subform should be automatically populated with the corresponding value.

To achieve this, we need to write a Deluge script during On User Input of Shoes, as shown in the below steps:

Step 1
Go to Edit this application in the top right corner of your application, click the + to create a new workflow, and select While using the form. You'll see another popup window now.





As shown above, select the form that you need to run the workflow on—in this case it's Mainform—select the option Created, and enter the name for your workflow.

Step 2
Click Add New Action, select Deluge Script, select On User Input, and then select the subform that you want to use.




Step 3
Before you write the script for your workflow, there are few things you need to do to ensure your workflow runs perfectly.
  • Declare a row variable for the respective subform in the main form
  • Assign values to the subform field by using the row variable
  • Declare a collection variable 
  • Insert the row variable into the collection variable
  • Insert the collection to the subform
Now, let's key in the script:


Let's see what we've done here in detail:

  1. if(input.Shoes=="Puma") // The if statement helps you validate the input
  2. {
  3. row1=Mainform.SubForm(); // Declares a row variable, which belongs to the respective subform in a main form
  4. row1.Currency=100.00; // Assign value to the subform field
  5. rows = Collection(); // Declares a collection variable to hold the rows
  6. rows.insert(row1); // Inserts the row variable into the collection variable
  7. input.SubForm.insert(rows); // Inserts the collection in the subform
  8. }
  9. else if (input.Shoes=="Nike")
  10. {
  11. row1=Mainform.SubForm(); // Declares a row variable which belongs to the respective subform in a main form
  12. row1.Currency=200.00; // Assigns a value to a subform field
  13. rows = Collection(); // Declares a collection variable to hold the rows
  14. rows.insert(row1); // Inserts the row variable into the collection variable
  15. input.SubForm.insert(rows); // Inserts the collection to the subform
  16. }
And don't forget to click Save to save your workflow! Click on Access the application to see how this works.

Step 4

Now it's time for the magic. Let's select a shoe we like from the dropdown field.




You can see that when Nike is selected, it now automatically populates a row with its values.

We hope from now on you use this tip whenever you use subforms in your application!  If you have any questions, feel free to ask in the comments below, and we'll be happy to address them soon!









                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation


                                        Manage your brands on social media



                                                Zoho TeamInbox Resources

                                                  Zoho DataPrep Resources



                                                    Zoho CRM Plus Resources

                                                      Zoho Books Resources


                                                        Zoho Subscriptions Resources

                                                          Zoho Projects Resources


                                                            Zoho Sprints Resources


                                                              Qntrl Resources


                                                                Zoho Creator Resources


                                                                  Zoho WorkDrive Resources



                                                                    Zoho Campaigns Resources

                                                                      Zoho CRM Resources

                                                                      • CRM Community Learning Series

                                                                        CRM Community Learning Series


                                                                      • Tips

                                                                        Tips

                                                                      • Functions

                                                                        Functions

                                                                      • Meetups

                                                                        Meetups

                                                                      • Kbase

                                                                        Kbase

                                                                      • Resources

                                                                        Resources

                                                                      • Digest

                                                                        Digest

                                                                      • CRM Marketplace

                                                                        CRM Marketplace

                                                                      • MVP Corner

                                                                        MVP Corner




                                                                            Design. Discuss. Deliver.

                                                                            Create visually engaging stories with Zoho Show.

                                                                            Get Started Now