Creating a Simple Store Application using Creator
One of the frequent questions we get is how to assign a number value
to a specific product/service and calculate price. As stated by a customer,
"I have a form to enable my clients to register for a specific service,
from the list of services offered and the dates on which the service is
required. Is it possible to assign rates to each service and create a
formula to give them an estimated price, based on the service selected?"
This topic illustrates how to create a simple store application in
creator and calculate price, based on the selected product/service.
About the application
Deluge Script
Related application
About the application
The Invoice
Application basically demonstrates price calculations based on
the product/service selected by the client. The application comprises
of the following forms:
- Add New Client form to register the client details like name,
email address, phone etc.
- Service Rates form to enter the rate for each service offered.
- Add Client Service form is used by clients to book of a specific
service. Only registered clients can book for a service. When a client
books for a specific service for specific dates, the total amount is
calculated and displayed in the Total Amount field, as shown in the
screen-shot below:
Deluge Script
The amount is calculated by writing "on user input"
script to the ServiceEndDate field of the Add Client Service
Form.
Add Client Service -> ServiceEndDate -> on user input
must have ServiceEndDate ( displayname = "Service End Date" type = date on user input { if (input.ServiceEndDate < input.ServiceStartDate) { alert("Please select a data greater that the service start date"); } else { r = Service_Rates [Service == input.Service]; tot_days = ((input.ServiceEndDate - input.ServiceStartDate) / 86400000); if (tot_days < 1) { tot_days = 1; } input.Total_Amount = ((r.Rate * tot_days)).toLong(); input.Amount = "The total amount to be paid for " + tot_days + "days is " + input.Total_Amount; } } )
|
Code Explanation:
1. The on user input script will be executed when a date is
selected from the Service End Date field.
2. The If condition checks for the validity of the start and end
dates.
if (input.ServiceEndDate < input.ServiceStartDate)
{
alert("Please select a data greater that the service start date");
}
3. Here, r is the collecton variable which stores the record from
the Service Rates form for the selected service.
r = Service_Rates [Service == input.Service];
4. The number of days is calculated based on the start date and end
date specified.
tot_days = ((input.ServiceEndDate - input.ServiceStartDate)
/ 86400000);
5. The Total Amount field is updated with the required calculations,
where, r.Rate returns the rate from the variable r.
input.Total_Amount = ((r.Rate * tot_days)).toLong();
5. The notes field "Amount" displays the specified text.
input.Amount = "The total amount to be paid
for " + tot_days + "days is " + input.Total_Amount
To view the script,
- Copy the application using the Copy Application link displayed
on the top-right corner.
- Select the Script tab
- Select the "Add_client_service" form from the Forms
tab
- Click on Field actions -> ServiceEndDate -> On user
input, to view the script.
Related applications
1. Refer the Freight
Forwarders sample application that calculates the total cost of
shipment based on the data that customers input and sends an email to
the client with the shipping quote, when the form is submitted. The
application comprises of two forms:
- The CountryRates form, to enter the Country name, the corresponding
freight cost and the number of days required for delivery.
- The Order form, where the user inputs the order details. The
total amount is automatically calculated and an email is sent to
the client.
|