onDialogInitialize

Arguments

RequestPointer

The Request object. Includes Request.Variables, which should be used instead of the older e.rv construct.

SessionPointer

The Session object. Should be used instead of the older e.session construct.

ePointer

An object that contains the following properties:

tmplPointer

Component definition

rtcPointer

Runtime calculations. You can use this to store data to be passed to other server side events.

The 'rtc' object cannot be used to persist state information - i.e. you can't set a value in rtc and then read that value in a subsequent callback. To persist state info see e._state
argumentsSQL::Arguments

SQL::Arguments object with values for each of the arguments defined in this component. To read a value from arguments: e.arguments.find("argumentName").data

You can also set the value of an argument. For example: e.arguments.set("country", "portugal")
javascriptCharacter

JavaScript to execute. The e.javascript property can be used to return JavaScript to the client for execution. The property will not exist until you assign a value to it. The JavaScript must be specified as a character string. See "Using JavaScript to set the Initial Value for a Large Number of Controls" and "Converting Dot Variables to JSON" below for examples.

Description

Fires the first time the UX Component is run.

Discussion

The onDialogInitialize event executes the first time a UX Component is run. This event is used to set initial values as well as Xbasic variables that contain data used to populate dropdowns, checkboxes, and radio button controls. JavaScript can be returned from this event by setting the e.javascript variable.

If the UX component is opened using Action Javascript, the onDialogInitialize event will not fire every time the component is opened if the action has been configured to cache the UX. The onSynchronize event can be used in this case to perform calculations on subsequent displays of the UX -- including setting the initial values of controls.

Setting Initial Values

You can set the initial value of any field by setting the property. For example:

e.control.firstname = "Fred"
e.control.lastname = "Jones"

For multi-valued controls (such as checkbox, List control configured as multi-select, etc.) you can set the value to a cr-lf list of values or use the special array() syntax. Either of the following two methods will work

e.control.colors = "array(red,green)"
e.control.colors = comma_to_crlf("red,green")

To set the value of a field in a repeating section, you must use "_A5INSTANCE" and the instance number as a suffix on the field name. For example, the following code sets the value of the firstname field in the 2nd row of the repeating section.

e.control.firstname_A5INSTANCE2 = "Bob"

Arguments

If the UX has arguments, the value of the arguments can be accessed via the e.arguments property. For example:

if (e.arguments.argumentNumber("country") <> -1) then
    country = e.arguments.find("country").data
end if

To set an argument:

e.arguments.set("country","portugal")

Returning JavaScript

To specify any javascript that you want to execute set the e.javascript property. For example:

e.javascript = "alert('hello');"

Setting State Variables

You can set 'state' variables in this event. The value of any state variables will be available in all subsequent ajax callbacks. To set a state variable:

e._state.myvar1 = "value1"
e._state.myvar2 = "value2"

Using JavaScript to set the Initial Value for a Large Number of Controls

This approach is recommended For Maximum Efficiency.

When setting the value of a large number of controls, you will improve performance if you generate the Javascript directly, rather than setting properties in the e.control object (as described above) and then having Alpha Anywhere generate the JavaScript from this object. The following example shows JavaScript code that sets the number of rows in a Repeating Section and sets the value of various control in the top section and Repeating Section of the UX:

dim js as c
js = <<%txt%
var rows = 7;
var setFocusToFirst = true;
var nullOutExistingData = true;
var repeatingSectionId = 'CONTAINER_1';
{dialog.object}._setRepeatingSectionRowCount(repeatingSectionId,rows,setFocusToFirst,nullOutExistingData);
var _d = {};
//Next command is optional. It is ONLY needed if the ._setRepeatingSectionRowCount() method
//has been called. The command copies default values into the _d object.
//Without this command, default values defined in the component will not be set.
//$u.o.assign(_d,DLG1_DlgObj.originalValues[0]);
_d['B'] = 'alpha'; //set the value of a control called 'B'
_d['E:2'] = 'beta'; //set the value of a control called 'E' in the 2nd Repeating Section row
_d['G:6'] = ['Red','Green']; //set the value of a checkbox called 'G' in the 6th Repeating Section row to 'Red' and 'Green'
{dialog.object}.prepare();
{dialog.object}.populate(_d);
{dialog.object}.refreshClientSideComputations();

%txt%

e.javascript = js

If the {dialog.object}._setRepeatingSectionRowCount() method is called in the onDialogInitialize event, you are responsible for setting values in ALL of the controls in the component. For example, if you have defined default values for some controls, and then set the values of other controls using the {dialog.object}.populate() method, only the values set in the _d object will be set. (The default values will NOT be set). You can, however, put the default values into the _d object using this code:

$u.o.assign(_d,{dialog.object}.originalValues[0]);

Converting Dot Variables to JSON

You can use the Xbasic varToJSON() function to help generate the Javascript object passed to the .populate() method. For example:

dim j as p
j.firstname = "John"
j.lastname = "Smith"
j.quantity_a5instance1 = "2"
dim j.colorchoices_a5instance2[3] as c
j.colorchoices_a5instance2[1] = "Red"
j.colorchoices_a5instance2[2] = "Blue"
dim jsTxt as c
jsTxt = varToJSON(j)
js = "{dialog.object}.populate(" + jsTxt + "); {dialog.object}.prepare();"

Simulating Session Variables

To simulate session variables when running in Working Preview you can use this code:

if eval_valid("request.SERVER_PROTOCOL") then 
    if request.SERVER_PROTOCOL = "A5RES" then 
        'running in working preview
        session.var1 = "simulated value for var1"
    end if
end if

See Also