Script example: RunDocumentPackTemplate script

In this section, you can view another KCM Core script call installed with KCM Core. You can use the RunDocumentPackTemplate script to create Document Packs from a Document Pack Template.

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

    The Script Editor window appears.

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

    Parameter Text DocumentPackTemplate;
    Parameter Text Result = "documentpack.zip";
    Parameter Text Environment = "";
    Parameter Text DBB_XMLInput = "";
    

    To create a Document Pack, you need to create a session that is associated with the active job and has a unique storage area. The session is no longer needed when the job ends, so the parameter Persistent is set to false. The script is started with a comment containing a short description of the script.

    /***********************************************************
     * Create a Session.
     * The Session can be removed when the Job ends 
     * so Persistent is set to false
     **********************************************************/
    CreateSession
       Persistent(false);
    

    KCM needs to store the result of the Document Pack Template run in a temporary result file before returning it. To allow a user to open multiple results, 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 _uniqueid 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);
    

    Use the CreateDocumentPack command to set up a new Document Pack.

    /***********************************************************
     * Create a new document pack 
     **********************************************************/
    CreateDocumentPack Name ("pack");
    

    The ITPRun command creates the content of the Document Pack based on a Document Pack Template. The information in the template determines what content is created. OutputMode ("pack") indicates that the result is a Document Pack. The local constant _document_pack points to the Document Pack.

    /***********************************************************
     * Run the Document Pack Template
     * This creates the content for the Document Pack
     **********************************************************/
    ITPRun
          Model (DocumentPackTemplate)
          Result (_document_pack)
          Environment (Environment)
          OutputMode ("pack")
          DBB_XMLInput(DBB_XMLInput);
    

    The ITPRun command results in a directory tree containing the content of the Document Pack. Use the SaveDocumentPack command to write the active Document Pack to a file.

    /***********************************************************
     * Save the Document Pack to the previously created 
     * filename
     **********************************************************/
    SaveDocumentPack
           File (ResultFile);
    

    Clean up the Document Pack.

    /***********************************************************
     * Close the Document Pack
     **********************************************************/
    CloseDocumentPack;
    

    You can use the SendFile command to upload the resulting Document Pack file to the client application.

    /***********************************************************
     * Return the result file.
     **********************************************************/
    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.