IterateDocumentPack

Use the command IterateDocumentPack to iterate through documents in the active Document Pack. For each document, a script is called to perform actions.

The command IterateDocumentPack fails if there is no active Document Pack in the session.

Syntax

IterateDocumentPack
	    Script (<text>)
	    Context (<text>)
	    Status (<text>)
	    Slot (<text>)
	    Channel (<text>)
	    Type (<text>)
					DelayErrors (True or False);

Parameters

  • Script: Required. The script that is called for each document in the Document Pack.
  • Context: Required. This value is directly passed to the Context parameter of the script.
  • Status: Optional. Filter. If this parameter is omitted, all formats are processed.
  • Slot: Optional. Filter. If this parameter is omitted, all slots are processed.
  • Channel: Optional. The channel that the script iterates over. If this channel does not exist in the Document Pack, no iterations are performed. If this parameter is omitted, it is empty, or has the special *default value, then the default channel will be iterated. To iterate over all channels, specify the special *all value.
  • Type: Optional. Filter.
  • DelayErrors: Optional. Indicates whether a failure in the iterator script should cause the iteration to terminate immediately or keep processing documents. If this parameter is omitted, processing stops immediately if an error occurs.

The command IterateDocumentPack processes all records in the manifest of the active Document Pack as it was at the time the command was called. The processing script is allowed to modify the contents of the Document Pack, but this does not affect the iteration. The processing script is allowed to use the command IterateDocumentPack recursively.

The parameters Status, Type, Slot, and Channel are used to select documents for processing. Documents that do not match the parameter are ignored during the iteration.

The Status parameter can have one of the following values:

  • "T" to select the original output of the template.
  • "I" to select import documents.
  • "A" to select alternative formats of the output. There can be multiple alternative formats associated with a template, resulting in multiple calls to the script.

The command IterateDocumentPack requires a script with the name indicated by the Script parameter. This script can define the following parameters:

  • Document. The fully qualified path to the document in the session directory or "*none" if there is explicitly no document produced for the channel.
  • Template. The KCM template that produced the document.
  • Type. The output type of the document.
  • Slot. The slot in the Document Pack.
  • Channel. The channel. This parameter is empty for the default channel.
  • Status. Type of the document.
  • ClosedLoopIdentifier. The value of the Closed Loop Identifier for this entry.
  • Flags.
  • Metadata. The fully qualified path to the Metadata XML file. This parameter is empty if there is no metadata written.
  • DataBackbone. The fully qualified path to the Data Backbone XML that was produced when the template was processed. This parameter is empty for static templates and import documents.
  • Context. The value of the Context parameter on the command.

All these parameters have type Text. Parameters can be omitted if the value is not used in the script.

Example

This example lists all slots in the Document Pack.

IterateDocumentPack
     	Script (ListSlots)
	     Channel (“”)		     # Filter default channels
	     Context (“TI”);		  # Passed to the iteration script.
					                    # Select Templates and Imports, ignore
																									# converted alternatives.

The ListSlots.dss script.

Parameter Text Slot;
Parameter Text Status;
Parameter Text Context;
/* Ignore other parameters. */

# List Slots whose Status is in the Context list.
If index (Context, Status) > 0 Then
	Progress Message (Slot);
Fi;

If any call to the iterator script ends in an error, the command IterateDocumentPack immediately fails. You can set the DelayErrors parameter to True to continue processing and delay the failure until after all alternatives have been processed.

When errors are delayed, the value of the _message global constant is undefined.