DataLoad
Overview
Creating Scripts
Event Handlers
How to...?
PHP Functions
Oracle Library
Character Encoding

User Guide Home
DataLoad Home

Creating a DataLoad Script

DataLoad scripts can be used with all DataLoad loads, that is Macro and Forms Playback loads as well as purely scripted loads.

To create a new script or view an existing script, click on the Script tab just above the DataLoad spreadsheet. The DataLoad script editor will appear. If no script currently exists DataLoad will ask whether a new script should be created. Answer "Yes" to this prompt. The DataLoad template script containing the event handlers will be added. PHP code may then be added to the event handlers as required. DataLoad contains a basic script editor. The script can be edited in a more advanced external editor by selecting "Editing Notepad++" from the Script menu or by clicking the edit button on the scripting toolbar.

While the script's code is visible an additional menu called "Script" will be available in DataLoad. To start the script for the first time select "Start Script" from this menu. In future the script will be started automatically when the DataLoad file is opened and it won't be necessary to manually start the script.

To create a very simple script, find the OnOpenFile event handler in the script and add the line below to this function. The code should be added anywhere between the the function's braces "{}" and on its own line. The OnOpenFile event handler can be found by looking for "function OnOpenFile()".

MessageBox("Hello world!");

The MessageBox() function is one from the library of functions provided with DataLoad that enables you to get or set spreadsheet data and control behaviour in DataLoad. MessageBox() causes a pop-up message to be shown in DataLoad and there are a range of parameters to control the message style. The OnOpenFile event handler runs when the DataLoad file is opened and when the script is started manually. Having added the above line to the event handler you should start the script (Script -> Start Script) and a pop-up box will appear containing the message "Hello World!". Your PHP script is now running and has executed the OnOpenFile event handler.

If the script is changed while it is running it is necessary to restart the script for the changes to become effective. This is done by selecting "Reload/Restart Script" from the "Script" menu. If the script has changed and is not restarted before the user leaves the script editor then DataLoad will ask if the script should be restarted . The script need not be restarted but that will mean the changes do not take effect until it is next restarted.

When the template script has been loaded PHP code can be added to the event handlers. If required at any time the script can be deleted and the template script re-installed by selecting "Load template Script" from the Script menu. That is not normally required but is available if you wish to start again from a clean template.

Beneath the script editor is a console where script errors, warnings and other information are shown. It is generally not required to view this console when a load is being used, however this console does provide useful information during script development and debugging, e.g. relating to errors and warnings.