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:
- if(input.Shoes=="Puma") // The if statement helps you validate the input
- {
- row1=Mainform.SubForm(); // Declares a row variable, which belongs to the respective subform in a main form
- row1.Currency=100.00; // Assign value to the subform field
- rows = Collection(); // Declares a collection variable to hold the rows
- rows.insert(row1); // Inserts the row variable into the collection variable
- input.SubForm.insert(rows); // Inserts the collection in the subform
- }
- else if (input.Shoes=="Nike")
- {
- row1=Mainform.SubForm(); // Declares a row variable which belongs to the respective subform in a main form
- row1.Currency=200.00; // Assigns a value to a subform field
- rows = Collection(); // Declares a collection variable to hold the rows
- rows.insert(row1); // Inserts the row variable into the collection variable
- input.SubForm.insert(rows); // Inserts the collection to the subform
- }
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!
Sticky Posts
ANZ In-Person Zoho User Group Meetups: Focusing on Zoho Creator & Zoho Flow (September 2024)
Hello, Zoho Community! Calling all Zoho users in Australia! We're thrilled to announce the next series of Zoho User Group (ZUG) Meetups, continuing the success of our previous sessions. These meetups are a great opportunity to learn, network, and engage
[SESSION ENDED] Ask the Experts #07| Live Q&A: Building workflows with Blueprint in Zoho Creator |
Hello, Post the release of Zoho Creator Blueprint last month, we're happy to tell you that we'll be launching a new 'Ask the Experts' session on 16th September (Thursday) this month focussing on creating blueprints in Zoho Creator. The session will be
Zoho Creator Community Webinars | October - November 2020 [Completed]
Hello everyone, I’m happy to announce that Zoho Creator is hosting a new Community Webinar Series starting this October. This series is a learning initiative aimed at our developer community, where every session will take spotlight use cases focused on
Community Learning Webinar - Zoho Creator Blueprint & other release updates | July 29, 2021
Dear developers, This June, the Creator team unveiled a slew of updates including UI enhancements to the Detail View of reports, an new capabilities in Data Import and Connections, and most important of all, the release of Blueprint in Creator. Customize
Community Learning Webinar: Delve deep into the core concepts of Zoho Creator | 17th June, 2021
Dear developers, Every customer has unique business needs and unique problems to solve. To be able to give solutions to these problems, to get over any stumbling blocks and to be able to build applications expeditiously that tailor to specific needs,