Tip 20: How to autopopulate values in a subform

Tip 20: How to autopopulate values in a subform



Hey folks,

We know that many of you use subforms extensively in your applications, as it helps you get the job done more efficiently. In this tip, we'll show you how to autopopulate values in the subform using a special syntax called "row."

Let's look at an example.

Consider you have an application where you need to automatically display the price of the product in the subform field based on the choice selected when a user clicks Add New in the subform. Let's say you have a form called "Mainform" that 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 below.






In order to autopopulate the price in the currency field when Add New is clicked in Subform, you need to follow these 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 or Edited, and provide a name for your workflow.

Step 2 

Click Add New Action, select Deluge Script, select Subform on add row, and then select the subform that you want to use.


















Step 3
Now, drag and drop the If else code snippet to perform the desired action.

This script will be executed in this manner: if the brand selected is "Puma", then the respective row's currency field value will be set to "100" using the keyword "row." And if "Nike" is selected, then "200" will be set as the value. If you have more products that you want to display in your dropdown, then you can make use of the nested if else statements. 

And don't forget to click Save to save the workflow!  





Now, let's access the application to see how this works.
.




Now, change the value in Mainform and click on Add New in SubForm—the corresponding value related to Mainform will be autopopulated.




And now you're all set!

In this tip, we discussed how to autopopulate values in subform rows when a user clicks on Add New in the subform. In our next tip, we'll be discussing how you can use Insert subform rows dynamically to autopopulate an entire row in the subform.

We hope this post was useful! If you have any questions, feel free to ask in the comments below, and we'll be happy to address them soon!