RunMdl; script example

To get a feeling for ITP/Server Scripts, take a look at the script of the RunMdl Service. If you have installed ITP/Server this script is also installed. To view the script, start the ITP/Server Administrator and select the Services node in the tree view. On the tab Services, select the RunMdl service and click the button Edit script. The Script Editor will open, showing the RunMdl script.

Note

Be careful, what you see is the actual script; any changes can and will affect the RunMdl service.

/*
 * RunMdl script. This script is an example that provides
 * default behavior. Use "as is" or adapt to your needs.
 */ 

The script starts with a comment containing a short description of the script. This is always a good idea to incorporate.

Parameter Text Model;
Parameter Text Result = "result.doc";
Parameter Text Keys = "";
Parameter Text Extras = "";
Parameter Text Environment = "";
Parameter Text MetaData = "";

The parameter block defines all expected parameters. It specifies defaults for all parameters except Model. Parameters that have default values may be omitted when the script is called.

/***********************************************************
 * Construct a unique filename for the result in the temp dir.
 * We declare the file to be temporary!
 **********************************************************/

Const Text ResultFile = ("result" + _uniqueid)[TempDir, "doc"];
Temporary File (ResultFile);

ITP needs to store the result document of the model run in a temporary result file before sending it away. In order to avoid conflicts, the names of these temporary files must be unique. In the above code, this is done by including _uniqueid in the file name. _uniqueid is a so-called Local Constant. It provides a unique value every time it is called.

/***********************************************************
 * Install the standard ITP error handler, run the ITP model,
 * and remove the error handler. 
 **********************************************************/

ITPErrorReset;
OnError
      Script (ITPError)
      Model (Model);

ITPError is a command that is part of ITP/Server. This command can be used as an error handler in all scripts running ITP.

ITPRun
      Model (Model)
      Result (ResultFile)
      Keys (Keys)
      Extras (Extras)
      Environment (Environment)
      MetaData (MetaData);

ITPRun is the script command that can be used to run ITP Models.

OnError Script(-);

This command will disable any previous OnError command and reactivate the standard error handling.

/***********************************************************
 * Return the result document.
 **********************************************************/

SendFile
      Src (ResultFile)
      Dest (Result);

The command SendFile can be used to send files to the client application that called the ITP/Server service. In this case, we send the result document of the ITP Model run to the client.

We recommend that you follow the layout of this script:

  1. Use a comment block to add a title and a short description.
  2. Start the script with the parameters.
  3. Place every command on a new line.
  4. If a command has multiple parameters, put each parameter on a separate line. Indent the parameters to facilitate reading.