Feedback

Events

onApplicationInit

This event occurs once only when the application is loaded.

First non-formal event executed, being triggered before the assembly of SQL and HTML.

It works as a preparation for an application, since it is possible among other things, various manipulatives, performs validations and changes a connection with a macro sc_change_connection, for example.

See below an example of how you use it.

 


No example below, or form_orders will be altered according to the user accessing the system.

If variable [usr_login] is equal to admin, or user will have access to or form with the possibility of inserting and excluding a registration.

If a variable has some other value, or user still has access to the form, therefore, only with a possibility of altering a registry.

Code example

if ([usr_login] == 'admin') {

    sc_apl_conf ("form_orders", "insert", "in");

    sc_apl_conf ("form_orders", "remove", "activated");

} else {

    sc_apl_conf ("form_orders", "insert", "off");

    sc_apl_conf ("form_orders", "remove", "off");

}

onNavigate

This event occurs when navigating among the records.

In the form, this event is always executed when performing a navigation, through the navigation buttons, navigation by page or the option go to.

OnScriptInit

This event occurs when the form its initialized. These formulas are executed before the application starts. At this moment, the application locals variables are not available.

onLoadRecord

This event occurs when the form it loaded. This event is executed before the form is loaded. In this moment all the applications variables are available.

onLoad

This event occurs when the form it loaded. This event it executed before the form is loaded. In this moment all the applications variables are available.

onRefresh

This event occurs when the form its reloaded.

This event occurs when the form application is reloaded, is possible to reload the form based on fields (select, radio, checkbox) or using the toolbar's Refresh button

onValidate

This event occurs during the data validation in a form application.

This event is executed when the form is submitted to the server, using the buttons: "add", "change" or "delete"
In this event, it is allowed to perform validations before the form data is sent to the database.



In the example below, using the form_orders application, we will validate the freight field, where if the value assigned to the freight field is greater than 30, an error message will be triggered to the user and the form submission will be cancelled.


Code example:
if({freight} > 30){
  sc_error_message("Shipping value is too high");
}

onValidateFailure

This event occurs when there is a validation error.

This event occurs when submitting the application in OnValidate, has errors generated by macros sc_error_exit, sc_error_message, or error detected by scriptcase (errors related to Database).

onValidateSuccess

This event occurs when there is no validation error.

This event occurs after submitting the form and executing the onValidate event, so if the validation is successful and contains no errors, generated by the sc_error_exit or sc_error_message macros, the onValidateSuccess event is executed.

onBeforeInsert

This event occurs before add a new record on the form application.

This event occurs after form validation (onValidate and onValidateSuccess), when clicking the Insert button, and before executing the SQL command to add the record to the database.

 


Example: We check the user privileges table before inserting the record, if he does not have privilege, we should send an error message.

sc_lookup(priv_ins," select priv_ins from tb_privileges where login = [var_login] ");

if({priv_ins [0][0]} != 'YES'){

  sc_error_message(" you do not have privileges to perform this operation ");

}

onAfterInsert

This event occurs after a row is added on a form applications.

This event occurs after clicking the Insert button on the form. The form will execute the onValidate, onValidateSuccess and onBeforeInsert events, and right after executing the SQL command to insert the database record, it will execute the onAfterInsert event.

 


Example: After the inclusion of a record in the database, we want to store the inserting operation in a log table.

sc_exec_sql(" insert into log values ([glo_user],'target table','insert',{key_field}) "); //insert the user id that was stored in a session variable [glo_user] and the newly added registry key {key_field}.

onBeforeInsertAll

This event occurs before add a new record on a multiple register form application.

This event occurs after clicking the Insert button of the multiple record form. The form will execute the onValidate and onValidateSuccess events, then it will execute the onBeforeInsertAll event before starting the execution of the SQL commands to insert the records into the database.

 

Note: This event is triggered only once, regardless of the number of lines inserted in one click on the Insert button.


Example: We check the user privileges table before inserting the record, if he does not have privilege, we should send an error message.

sc_lookup(priv_ins," select priv_ins from tb_privileges where login = [var_login] ");

if({priv_ins [0][0]} != 'YES'){

  sc_error_message(" you do not have privileges to perform this operation ");

}

onAfterInsertAll

This event occurs when a record its added on a multiple register form.

This event occurs after clicking on the Insert button of the multiple record form. The Form will execute the onValidate, onValidateSuccess and onBeforeInsertAll events, and then it will execute the onAfterInsertAll event after execute all the SQL commands to insert the records into the database.

 


For example, after entering the items of an invoice, (tb_itens_nf), in a multiple-record form, include in the "parent" table (invoice_file) the total value of the products.

sc_lookup (tot, "select sum (item_value) from tb_itens_nf where num_nf = {num_nf}");

{tmp_tot} = {tot [0] [0]};

sc_exec_sql ("update tb_itens_nf set total_itens = {tmp_tot} where num_nf = {num_nf}");

onBeforeUpdate

This event occurs before the update of a record in a form.

This event occurs after form validation (onValidate and onValidateSuccess), when clicking the Save button, and before executing the SQL command to Update the record in the database.

 


Example: We are checking the user privileges table before updating the record, if it does not have such privilege, we send an error message.

sc_lookup(priv_upd ," select priv_upd from tb_privileges where login = [var_login] ");

if( {priv_upd [0][0]} != 'YES'){

  sc_error_message("You do not have privileges to perform this operation");

}

onAfterUpdate

This event occurs after a row is updated on a form applications.

This event occurs after clicking the form's Save button. The form will then execute the onValidate, onValidateSuccess and onBeforeUpdate events, and right after executing the SQL command to insert the database record, it will execute the onAfterUpdate event.

 


Example: After updating a record in the database, we want to store the update operation in a log table.

sc_exec_sql(" insert into log values ([glo_user],'target table','update',{key_field}) "); //insert the user id that was stored in a session variable [glo_user] and the newly added registry key {key_field}.

onBeforeUpdateAll

This event occurs before the update of a record in a multiple register form.

This event occurs after clicking the Save button on the multi-record form. The form will then execute the events onValidate and onValidateSuccess, and then execute the event onBeforeUpdateAll before starting the execution of SQL commands to update records in the database.

Note: This event is triggered only once, regardless of the amount of rows updated in one click on the Save button.

 


As examples we can see in the example below, we consult a user privileges table before updating the record, if it does not have such privilege, we send an error message.

sc_lookup(priv_upd ," select priv_upd from tb_privileges where login = [var_login] ");

if({priv_upd [0][0]} != 'YES'){

sc_error_message(" you do not have privileges to perform this operation ");

}

onAfterUpdateAll

This event occurs when there is an update on a multiple row only on multiple rows forms.

This event occurs after clicking on the Save button of the multiple record form. The Form will execute the onValidate, onValidateSuccess and onBeforeUpdateAll events, and then it will execute the onAfterUpdateAll event after execute all the SQL commands to update the records into the database.

 


Example: We can update the total value of an invoice (tb_invoice) after update its items (tb_invoice_items) in a multiple records form.

sc_lookup (tot, "select sum(value_item) from tb_invoice_items where num_nf = {num_nf}");

{tmp_tot} = {tot [0] [0]};

sc_exec_sql ("UPDATE tb_invoice SET total_items = {tmp_tot} WHERE num_nf = {num_nf}");

onBeforeDelete

This event occurs before deleting a record on a form application.

This event occurs after form validation (onValidate and onValidateSuccess), when clicking the Delete button, and before executing the SQL command to delete the record in the database.

 


As examples we can see in the example below, we consult a user privileges table before deleting the record, if it does not have such privilege, we send an error message.

sc_lookup(priv_del," select priv_del from tb_privileges where login = [var_login] ");

if({priv_del[0][0]} != 'YES'){

  sc_error_messagem(" you do not have privileges to perform this operation ");

}

onAfterDelete

This event occurs when a register is deleted.

This event occurs after clicking the form's Delete button. The form will then execute the events onValidate, onValidateSuccess and onBeforeDelete, and then, right after executing the SQL command to delete the record in the database, it will execute the event onAfterDelete.

 


Example: After deleting the record we can easily create logs, according to the code below:

sc_exec_sql(" insert into tb_log values([glo_user],'exclusion','customer_table',{code}); //we are storing the literals 'exclusion' and 'customer_table', the session variable [glo_user] and the field variable {code} containing the deleted content of the code field.

onBeforeDeleteAll

This event occurs before deleting a record on a form application.

This event occurs after clicking the Delete button on the multi-record form. The form will execute the onValidate and onValidateSuccess events, then it will execute the onBeforeDeleteAll event before starting the execution of the SQL commands to delete records in the database.

Note: This event is triggered only once, regardless of the amount of lines removed in one click on the Delete button.

 


As examples we can see in the example below, we consult a user privileges table before deleting the record, if it does not have such privilege, we send an error message.

sc_lookup(priv_del," select priv_del from tb_privileges where login = [var_login] ");

if({priv_del[0][0]} != 'YES'){

sc_error_message(" you do not have privileges to perform this operation ");

}

onAfterDeleteAll

This event occurs when a register is deleted on multiple rows forms.

This event occurs after clicking no button Exclude form multiple records. Or the form will execute the onValidate, onValidateSuccess and onBeforeDelete events, and the logo will execute all the SQL commands to exclude the records not the data bank, it will execute or the onAfterDeleteAll event.

Note: This event occurs only once regardless of the quantity of records excluded at a time.


Ex. In an order item form (multiple records), we want to delete the order if all screen items are deleted. Just in the event OnAfterDeleteAll use a block similar to the one shown below:

sc_exec_sql ("DELETE FROM orders WHERE order_id = {order}");

Scriptcase has Events to allow the developers to customize the application code. By using the events, the developers can program custom actions at a specific execution time (e.g. After a record is inserted, when it is loaded, upon submitting a Form, …) and for a specific application type. In the events area you can use global and local variables, JavaScript, CSS, HTML, PHP codes and also Scriptcase macros.

Scriptcase code editor is used within events and has a series of shortcuts to help in the applications development.

Scriptcase event editor

At the top section of the editor, there are some options that allows us to change the editor theme or expand it, for example. These options can also be activated using the hotkeys.

  • Full Scream - Increases the area occupied by your code editor.
  • Full Scream - Expand the sides of the code editor.
  • Search - Activates the search in the code editor.
  • Replace - Enables replace in the code editor.
  • Scriptcase event editor - Defines the code editor theme.

The hotkeys are available in all browsers compatible with Scriptcase.

Click Here to view the Scriptcase hotkeys documentation.