Checks and Functions

Checks and functions allow you to hook into particular actions performed with versions. This is done by means of Tcl code.

There are three checks and functions that can be specified in file formats: the completion check, the content assignment function, and the or workflow modification function. Two ways to open the form in which they can be edited exist: If you are about to create a file format, click on the Checks and Functions button in the Other Options section in the corresponding form. However, if you would like to modify them in an existing file format, localize the file format first in the File Formats section using the search function. Click on the file format name in the list entry to switch to the view page of the file format and there on the Edit button to switch to the editing form for file formats. Here, click on the Checks and Functions button in the Other Options section of the form to open the corresponding form:

Version assignment function

The Content Management Server calls up the version assignment function before it sets a version’s field values. This occurs after you have edited the fields in a field set or the main content of a content. The function is called after the value assignment functions of the individual fields have been executed. Your Tcl code only has access to the Content Management Server data in read-only mode. The function code can use the following variables:

  • modifiedAttributes: The list of version fields and their values that are to be changed by the write operation, encoded as name-value pairs. The blob of the content is not contained in this list.
  • contentId: The ID of the content whose fields are to be changed.
  • inBlobFile: The name of the file in which the function finds the blob in case it has been modified. If the blob has not been changed, this variable is undefined.
  • outBlobFile: The name of the file to which the function must write the blob if it is changed. This file does not exist when the function code is entered. If the function creates it, the Content Management Server sets the blob to its contents.
  • result: On successful execution, this variable should be set to 1 , and otherwise to 0 by the function to signal the execution status to the Content Manager.
  • messages: If result is 0, the Content Manager interprets the value of messages as an error message to be output.

You can use your code to check the consistency of the field values and, if necessary, change the modifiedAttributes list. Please note that the main content of a version is referenced separately via the inBlobFile and outBlobFile variables. This is shown in the following example for a main content containing text:

if {[info exists inBlobFile]} {
    set fh [open $inBlobFile r]
    fconfigure $fh -encoding utf-8
    set blob [read $fh]
    close $fh

    ### Code modifying the blob and other fields goes here.
    ### Now, let’s store the blob in the provided file:

    set fh [open $outBlobFile w]
    fconfigure $fh -encoding utf-8
    puts -nonewline $fh $blob
    close $fh
    set result 1
}

If your code has set result to 1, the Content Management Server interprets the modifiedAttributes as field name-value pairs and stores the field values. Input values which are saved in an internal format (such as date values) are converted in this process. If, on the other hand, you set result to 0 (zero), the Content Management Server does not save the field values. In this case, the Content Management Server assumes that an error has occurred and that your code has stored one or more error messages in the messages list. The Content Management Server then displays these error messages.

Workflow modification function

You can use the code entered here to influence the workflow of a draft version before the content is created. It is called up when a file is created or if one of the workflow actions Edit, Reject or Unrelease is performed. Before the Content Management Server calls the code, it sets the contentId variable to the ID of the draft version concerned and the objId variable to the ID of the file to which the content belongs. Furthermore, the workflow parameters are stored in the workflow variable. These parameters result from the workflow assigned to the file format of the file. The parameters are stored in the workflow variable as a Tcl List. The elements of this list are:

  • editGroups editGroups
    editGroups
    is the list of user groups that are to edit the content.
  • signatureDefs signatureDefs
    signatureDefs
    is the list of signature definitions. Each definition is a list made up of two elements, the first element being the name of a signature field and the second element the name of the user group whose members are permitted to provide the signature.
  • allowsMultipleSignatures multiSig
    multiSig
    contains 0 if is not permissible for the same user group to sign a content more than once. Otherwise, the parameter contains the value 1.

Using your Tcl code, you can modify the workflow definition by saving it in the workflow variable. The following example illustrates how different workflows can be used depending on the path:

set path [obj withId $objId get path]
switch -regexp $path {
/intranet {set workflow {allowsMultipleSignatures 1 editGroups Intranet_Editors signatureDefs {{Sig_Chiefs1 Chiefs1}}}}
/internet {set workflow {allowsMultipleSignatures 1 editGroups Internet_Editors signatureDefs {{Sig_Chiefs2 Chiefs2}}}}
}

Completion check

Here you can enter Tcl code which the Content Management Server will execute after a draft version was modified. Among other things, the values of fields can be checked for consistency here.

The Content Manager Server only calls the code if all other completion checks have been successfully concluded or if the reasons for incompleteness need to be determined. The Content Management Server does not allow any write operations (such as changing a field value). However, variables can be set.

The following global variable is set by the Content Management Server prior to executing the code:

  • contentId: the ID of the version to be checked.

The result is returned by means of the following (global) variables:

  • result: 0 (zero) indicates that the version is incomplete. Other return values will be interpreted as complete.
  • messages: A list of messages indicating the reasons for incompleteness (string array)

After you have determined the checks and functions of the file format, click on OK to save the changes.