Adding Records using Add Record Task
Let us take the example of a simple expense tracking application to illustrate
the usage of the Add Record task. This application consists of the following
forms:
- Expense Form to enter your daily expense details.
- Monthly Payments Form to enter the monthly payments to be
made with due date for each expense. This form will have a decision
checkbox "Add to expense" which is hidden when the form is
loaded to add new monthly payments.
When a monthly payment is made, the user will update this record by checking
the "Add to expense" checkbox field. On update, the record will
be automatically added to the Expense form. This is achieved by
adding on success script to the actions -> on edit block.
The Monthly Payments form definition given below, highlights the
on success script added to the on edit block. The script
will be executed when a record is updated. The script will add a record
to the Expense form with the given values, if the "Add to
expense" checkbox is set to true.
form Monthy_Payments
{
displayname = "Monthy Payments"
Payment_due_on
(
displayname = "Payment due on"
type = text
)
Amount
(
type = USD
width = 20
)
Description
(
type = textarea
)
Add_to_expense
(
displayname = "Add to expense"
type = checkbox
defaultvalue = false
)
actions
{
on add
{
on load
{
hide Add_to_expense;
}
Submit
(
type = submit
displayname = "Submit"
)
Reset
(
type = reset
displayname = "Reset"
)
}
on edit
{
Update
(
type = submit
displayname = "Update"
on success
{
if (input.Add_to_expense)
{
insert into Expense_Form
[
Added_User = zoho.loginuser
Amount = input.Amount
Description = input.Description
Expense_Date = zoho.currentdate
]
}
}
)
Cancel
(
type = cancel
displayname = "Cancel"
)
}
}
}
|
|