Form Actions - On Success

 

Description

To perform any action when a new record is successfully submitted to the database or when an existing record is updated or deleted from the database, you need to write the on success script for a form. For example, to send a mail to the team lead as soon as a feedback is submitted, send a mail to the admin userid when a record is deleted.

By default, the message "Data Added/Edited Successfully" is displayed on successful submisson of form data. You can customize the success message by specifying the same in the success message string. Refer On success message for more information on customizing the success message.

Syntax

On success - On add : The on success script written inside the actions -> on add block within the Submit button is invoked when a new record is added to the database. The user supplied data is already in the database when this script is run.

actions
{
    on  add
{
Submit
(
type = submit
displayname = "Submit" on success
{
// write deluge script to be executed when a new form data is persisted in the database
.......
....... }

) }

On success - On edit : The on success action script written inside the actions -> on edit block within the Update button is invoked when an existing record is updated and persisted in the database. The user supplied data is already in the database when this script is run.

actions
{
    on  edit
{
update
(
type = submit
displayname = "Update" on success { //write deluge script to be executed when a new form data is persisted in the database
..................
}

) } }

On success - On delete : The on success action script written inside the actions -> on delete block is invoked when an existing record is deleted from the database. The record is removed from the database when this script is run.

actions
{ 
    on  delete
{
on success
{
//write deluge script to be executed when an existing record is deleted from the database
...............
}

}

Example

    Send Mail : In the below given feedback form sample, a mail is sent when a new form data is persisted in the database.

            form  Send_Feedback
            {
                displayname  =  "Send Feedback"
    
                sender
                (
                    displayname = "From"
                    type  =  email
                )
    
                mail_subject
                (
                    displayname = "Subject"
                    type  =  text
                )
    
                category
                (
                    displayname = "Category"
                    type  =  radiobuttons
                    values  =  {General,   Usability,   Bug Report,   Feature Request}
                )
    
                comments
                (
                    displayname = "Comments"
                    type  =  textarea
                )
             
                status
                (
                    displayname = "Status"
                    type = picklist
                    values = {Open, Closed, In progress}
                    private = true             
                )
    
               
            actions
    {
    on add
    {
    Submit
    (
    type = submit
    displayname = "Submit"
    on success
    {
    sendmail
    (
    From : zoho.adminuserid
    To : input.sender
    Subject : input.mail_subject
    Message : input.category+"<br>"+input.comments
    )
    success message "email sent";
    }
    )
    } } }

    Code Description

    In the above code, the sendmail function is added in the on success form action, where input.<fieldname> replaces the value specified in the form for the fieldname to the To:, Subject:, and Message: entries.

 

Related Links

Deluge Reference - Success message
Deluge Reference - Send Mail
Tips & Tricks - Send Mail Scenarios