Calling Custom Code Functions

In most applications there are a few cases where it’s useful to constrain a query based on values computed by your own custom code.  For example, in a customer portal application, you may want to calculate and display a customer’s available credit capacity.  You can write a custom function in C#, Visual Basic .NET or other .NET language that is called by your application.  Custom functions are available in several contexts.

Custom functions in WHERE clauses

Custom functions can be called from within your application’s SQL WHERE clauses when selecting and displaying data.  Custom functions return a value that is compared to the record's field value when that record is read at run-time.  Based on the comparison of the two, the record is either included in or excluded from the result set.

Use a custom function of your own to constrain the selection criteria to retrieve data.

Select your custom function in the Add WHERE Clause dialog, accessed from the Page Properties dialog, Query tab.  When Iron Speed Designer generates your application, it creates the “addFilter” mechanism that applies the comparison.

Custom functions should return values that appropriately match the left side of the filter clause.  It’s important to note that custom functions are not filtering functions themselves; they simply provide a value which is used by the generated filtering code when comparing record field values to the value returned by the custom function.

Custom functions in field initialization

Custom functions can be called when initializing FieldValue components.  Use your custom function to provide custom field initialization values.

Use a custom function when initializing a field.

Select your custom function in the Page Properties dialog, Bindings tab, Set Initial Value To section.

Usage contexts

Regardless of whether you are calling your custom function from within a WHERE clause or as part of a field’s initialization, the mechanism for adding your custom code and calling your functions from within your application are the same.  The only difference is the context in which function names are resolved.

Context

Description

WHERE clauses

Iron Speed Designer inserts function calls to your code into the appropriate generated code files.  Your custom functions must be accessible from there.

Field Initialization
(Set Initial Value To)

Iron Speed Designer inserts function calls to your code within "server control tags" in the generated page (a.k.a. "code in-fronts"), so your custom functions must be accessible from that context.

Typically, fully-qualified function names are accessible from both places, so the same function reference can be used both contexts.

For example, if your custom function is defined in the customizable classs of a ShowCustomersTable page, then the fully-qualified function reference would be:

ShowCustomersTable.MyFunction()

In this example, the function should be declared as "Public Shared".  If you have a separate function library included in the application, the function reference would be similar to:

MyLib.MyFunction()

See Also

Example: Calling a .NET Framework Function

Example: Calling a Custom Function in a Customizable Class

Passing Parameters to Custom Functions