How to update Unit Price into a subform based on Product selection

14.05.13 03:55 PM By FMRR

Understanding how to manipulate and work with subforms in Zoho Creator can drastically enhance the efficiency and functionality of your business applications. One such manipulation involves updating a unit price based on product selection within a subform. This guide will explain this procedure in detail.

The logic execution sequence for achieving this task in Zoho Creator is similar to adding a script to a regular form: On Add, On Delete, On User Input. However, there are subtle differences in the coding and how to embed the script into a subform.

Embedding Scripts in Subforms vs. Regular Forms

In a regular form, you have several scripting options such as Script Builder, Free Flow, and Form Definition. These options allow you to write the code manually if you are proficient in doing so. In contrast, a subform doesn't have a Script Builder. Instead, users must manually write the code using a Free Flow approach style.

The workaround is to write the code using the Script Builder in a regular form, save it from a free flow screen, and then insert it into the corresponding subform action.

Consider the image below, which displays an Order Management Form with standard product fields and its Unit Price. It also includes a subform that aggregates products in a similar manner. We created a script to update the Unit Price based on the Product selection for this example.

Comparing the code lines that update the fields on the right (regular form) to the ones on the left (subform), you'll notice they're nearly identical. This similarity provides a fantastic opportunity to quickly incorporate scripts into any subform.

Here's a practical tip: write the script on a regular form, then paste it into the subform and correct the subtle difference.

SCRIPT FOR REGULAR FORM ON USER INPUT FOR ORDER ITEM.
//Fetches the information from the "Products" table
selected_Product = Products ;
//Updates the value of Unit Price using the stored value from "Products" table
input.Unit_Price = selected_Product.Price;
SCRIPT FOR SUBFORM ON USER INPUT FOR ORDER ITEM.
//Fetches the information from the "Products" table
selected_Product = Products ;
//Updates the value of Unit Price using the stored value from "Products" table
row.Unit_Price = selected_Product.Price;
Notice that the only difference between the 2 is the word row. before the field value of the subform. With this knowledge you can now write the script you need on a regular form by simulating the subform fields, import the code and modify with the word row. as needed.

Key Takeaway

This process makes updating a unit price based on product selection in a Zoho Creator subform simpler and more streamlined. Don't forget to experiment with this method and tweak it according to your business needs.

For more detailed information on using Zoho Creator, check out our other blog posts or visit the official Zoho Creator documentation.

What is a subform in Zoho Creator?

A subform is a form within a form containing a set of questions. That specific set of questions can be duplicated or repeated dynamically within repeating sections. You can use the subform to collect multiple entries of the same category effortlessly.

How do I create a sub form in Zoho Creator?

Add subform field to your form Open the form builder. Add a subform field to the form. ( Refer to this page to learn how to add a field to a form) If your app does not have any additional forms, Zoho Creator will add a blank subform. ... Select the required choice from the dropdown, then click Done .

What is the subform limit in Zoho Creator?

The maximum number of subform fields you can add in a layout is 10. The maximum number of entries across all subforms on an aggregate is 200.

How do I get subform data in Zoho Creator?

The Field API names of the subform can be acquired using Fields Metadata API of the parent module. The Field API names of the individual fields in a subform can be acquired using Fields Metadata API, with the request URL as "fields? module={Sub_form_api_name}".

What is the purpose of subform?

The subform control provides properties which allow you to link the data displayed in the control to the data on the main form. The property of the subform control that determines what object is displayed in the control. A simple display of data in rows and columns, much like a spreadsheet.

FMRR