Script example: RunMdl script

To understand how KCM Core scripts are organized, you can view an actual KCM Core script call installed with KCM Core.

  1. Start KCM Core Administrator.
  2. In the tree view, click the Services node and select the Services tab.
  3. Click RunMdl and click Edit script on the right.

    The Script Editor window appears.

    The script is started with a comment containing a short description of the script.

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

    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.

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

    KCM needs to store the result document of the template 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 following code, this is done by including _uniqueid in the file name. _uniqueid is a so-called local constant, which provides a unique value every time it is called. For more information on the local constant, see Constants.

    /***********************************************************
     * 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);
    

    There is a script command called ITPRun that you can use to run templates.

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

    You can use the SendFile command to send files to the client application that calls a KCM Core Service. In this case, the result document of the template run is sent to the client.

    /***********************************************************
     * Return the result document.
     **********************************************************/
    
    SendFile
          Src (ResultFile)
          Dest (Result);
    

  4. Close the Script Editor and be sure not to save any possible changes that you may have made while viewing the script.