Level: Advanced Duration: 1 hour
Recap: Made enhancements to the order management application to calculate total price of an order, update available stock, create purchase order, create customized reports and learnt how to replace existing code with reusable functions.
In Tutorial 1, we created an order management app with the Order and Product forms and created a relationship between the forms using lookup fields.
In this tutorial, we will create the Order Management app using SubForms. (i.e) the Product Form will be added as a SubForm to the Order Form. A SubForm is a Form within a Form. It helps you submit related forms (with one-to-many relationship) in a single interface. The primary form is called the MainForm, and the Form that is inserted in the main form is called the SubForm. We will also learn about Script actions that can be performed on a SubForm.
Screen shot displaying Products Form
Now click on Create New - Form to create a form named Order. Insert the following fields in the Order Form:
The Order Form and the Products Form have been created. Now lets link the Products Form and the Order Form with the help of lookup field type.
Screen shot displaying Orders Form
SubForm actions are actions that are performed whenever a change is made in the subform. For example, SubForm actions can be performed when a row is added, deleted or when a SubForm field is filled in.
SubfForm actions include On Add row, On Delete row and On User input to make the SubForm functionality more useful.
Screen shot displaying SubForm Actions
The On Add row and On Delete row scripts get executed when a row is added or deleted in the SubForm.
The On User input script gets executed whenever the user adds data in the Subsorm. Let us see an example of the On User input script which calculates the total amount based on the product, price and quantity selected.
//Link the Product field in subform to the Product field in Products form
selected_Product = Products [ID = row.Product];
//Set the quantity of the selected product as per the Products form
row.Quantity = selected_Product.Quantity;
//Set the price of the selected product as per the Products form
row.Price = selected_Product.Price;
//Calculate the total amount based on the product, price and quantity.
tot = 0.0;
for each item in Products
{
tot = tot + (item.Price * item.Quantity);
}
input.Total_Amount = tot;
//Link the Product field in subform to the Product field in Products form
selected_product = Products [ID = row.Products];
//Calculate the total amount based on the product, price and quantity.
tot = 0.0;
for each item in selected_product
{
tot = (tot + item.Price * item.Quantity);
}
input.Total_Amount = tot;
The Products form has been added as a subform in the Orders form. The Total Amount field is configured with On User Input script to automatically calculate the total amount based on the product, price and quantity selected. Click on "Access this application" on the top right corner to go to the live mode.
Fill up the Products form and the Ordersform with sample entries. The Total Amount field displays the total amount based on the product, price and quantity selected.
Screen shot displaying the SubForm values with the Total Amount field displaying the calculated value
To view the data stored in the SubForm:
Screen shot displaying the subform values when we click on Google Nexus 4
Custom Actions are actions performed on selected records in a report by executing Deluge functions. For example, you can define a function to approve or reject an order request and configure this function as a custom action for a report. This action can be invoked for selected records in the report. In this topic, we will learn how to create a custom action to approve or disapprove an order.
Firstly, we will add a "Status" Field in the Order form with options "Approve", "Disapprove" and "Waiting for Approval".
Now we will create two functions and configure those functions as "Approve" and "Disapprove" custom actions. First let us create the two functions
Now let us configure these functions as "Approve" and "Disapprove" custom actions.
The functions have now been configured as custom actions. Let us access the custom actions in Live mode.
Pages are customized reports created using HTML tags and Deluge scripting. You can insert your form’s field variables into blank HTML pages and make excellent dashboards, presenting dynamic reports based on user selected criteria. The HTML Page Builder provides an intuitive drag-n-drop user-interface to easily create the required pages. You can use Pages to,
Lets see an example to create a search functionality using Pages. Using the search option, we will search for an order using the customer name. The returned record will contain the email address and the total amount of that particular order.
Create a Search Form with the Fields that would make up a Search Dialog. A search Form is basically a Stateless form, that does not store data in the ZC database.
Create the required html page with parameter, e.g.searchname, to pass the search key (specified in the above Search form). Write the code for this view to retrieve the records from your Table whose value matches the passed parameter.
//pass the parameter (searchname) declared in "Search order" stateless form
//fetch the record from "Order form"
//"Order_form" is the link name for the Order form
htmlpage Search(searchname)
<%{
name = Order_form [Name == input.searchname];
message = "";
if (name.count() > 0)
{
//iterate subform records
for each x in name.Product
{
// subform field name in the main form
message = message + x.Products;
// variable.Field_Name_In_The_Subform
}%>
//create a table to display the fetched records
//"Search_order" is the stateless form link name
<table>
<tr>
<td width="222px" valign="top">
<div elName='zc-component' formLinkName='Search_order' params='zc_FtrClr=_ffffff&zc_InpFieldWidth=100&zc_Header=false'>Please Wait...</div>
</td>
<td>
<table class="zc-viewtable" style="border:0px solid #75b5f2">
<tr>
<th>Order Details</th>
</tr>
<tr class="zc-row-header">
<th class="zc-viewrowheader">
Email
</th>
<th class="zc-viewrowheader">
Products
</th>
<th class="zc-viewrowheader">
Order Value
</th>
</tr>
<tr class="zc-viewrow zc-row-1">
<td><%=name.Email%></a></td>
<td><%=message%></a></td>
<td><%=name.Total_Amount.round(0)%></a></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>
</td>
</tr>
</table>
//display error if no records found
<div style="text-align: center;"> </div> <%}
else if ((input.searchname != null) && (input.searchname.length() > 0))
{%>
<h2>Name Not Present</h2>
<%}
}%>
Access the application in live mode to use the "Search" functionality
Note