Please enable JavaScript to view this site.

Navigation: Advanced topics > Events > Table events > Add page

Custom add

Scroll Prev Next More

Description

The CustomAdd event is executed before the record is physically added to the database. It is designed to replace the standard Add procedure.

 

Use it when you do not want record to be added to the table in question.

Syntax

public XVar CustomAdd(dynamic values, dynamic keys, dynamic error, dynamic inline, dynamic pageObject)

Arguments

Note: Field names are case-sensitive. If the field name is PlayerId, you should use values["PlayerId"]. Note that values["playerid"] or values["PlayerID"] will not work.

 

Note: If the field was assigned an alias in the SQL query, then the values array will get the alias instead of the field name from the database.

E.g., if you have an SQL query SELECT salesrep_id AS Inv_Salesrep ..., you should use values["Inv_Salesrep"].

 

values

an array of values to be written to the database. To access a specific field value, use values["FieldName"].

keys

an array of key column values that point to the new record. To access a specific key column, use keys["KeyFieldName"].

error

place the message to be displayed into this variable.

inline

equals to true for the Inline Add, false otherwise.

pageObject

an object representing the current page. For more information, see RunnerPage class.

Return value

True: if you want the application to handle adding the record.

 

False: if you have added the record with your code.

Applies to pages

Add, Inline Add.

Example

Lets consider the situation when records are never added directly to the main table (e.g., Cars).

 

Instead, records are added to the temporary TempCars table and then moved to the main Cars table once approved by the admin.

 

In this case, the following code in the CustomAdd event will do the job:

 

dynamic tblTempCars = GlobalVars.dal.Table("TempCars");
tblTempCars.Value["make"] = values["make"];
tblTempCars.Value["model"] = values["model"];
tblTempCars.Value["yearOfMake"] = values["yearOfMake"];
tblTempCars.Add();
return false;

 

Note: You may have noticed that the BeforeAdd event does the similar job. The main difference is that returning false in the BeforeAdd event is considered an error, and the user will see that something went wrong. Returning false in the CustomAdd event is perfectly legitimate, and application execution continues after that.

See also:

How to control Inline Add/Edit functionality from script

Javascript API: InlineRow object

After record added

Choose pages screen

About SQLQuery class

About SQLQuery screen

Additional WHERE tabs