This is an example of a policy enforcement hook for ClearQuest.


Rational staff, Staff, IBM

This article is brought to you by the Rational staff at developerWorks.

18 May 2004

This item was originally published in May, 2002.

NOTE: This hook is presented only as an example of how to customize your use of IBM® Rational® ClearQuest®. It has not been formally tested, and is not supported by IBM.


IBM® Rational® ClearQuest® Web supports uploading and viewing attachments just like native clients do, but is built in such a way that all other concurrent ClearQuest Web users on the same Web server will be frozen until the file upload/download is complete. One solution is to limit the size of the attachments before they are ever stored in the database. To accomplish this, we will depend on knowing a few facts about the inner workings of ClearQuest.

  • Attachments can be added whether the record is in an editable state or not, and through the API, but in all cases adding an attachment performs an action on the record.
  • The file upload is not done until that action is committed.
  • Between the time that the file was attached and the action is committed, that attachment's size when accessed via the CQ API returns 0 (this is how we can tell which attachments have just been added).

By creating a Base Action, we can create a single Validation hook that executes during the context of all other actions. We will inspect the file size of the attachment(s), and prohibit the action from being committed if any is over a certain limit.

First we iterate through all attachments, checking their size with the attachment.FileSize method. If it returns 0, we know that the file has been added during the current action, and is still on the local drive, so we check the FileSystemObject's filesize. If this size is larger than the limit, we return an error string from the validation hook, that aborts the commit. Returning an empty string allows the commit to proceed.

Script Language

VB Script


Base Action Validation hook:

Function Defect_Validation(actionname, actiontype)
  ' actionname As String
  ' actiontype As Long
  ' Defect_Validation As String
  ' action is AttachAuthorization
  ' record type name is ChangeRequest
   REM Return a non-empty string explaining why the action
   REM cannot commit with the current values.
   REM Or, if it is valid, return an empty string value.
   REM Example: 
   REM    Dim value_info
   REM    Set value_info = GetFieldValue("some field")
   REM    If Len(value_info.GetValue())   10 Then
   REM        Defect_Validation = "Must be at least 10 chars long"
   REM    End If

  Dim fso, f, s
     Defect_Validation = ""
     set session = GetSession()
     set attachFields = AttachmentFields

     ' Iterate over the attachment fields on an Entity.
     For Each attachField In attachFields
        set attaches = attachField.Attachments
        ' iterate over the attachment's field attachments
        For Each myAttach In attaches
              filename = myAttach.FileName
              filesize = myAttach.FileSize
              ' INFO "filenmae is " & filename
              ' File size is always 0 before a first commit
              If (filesize = 0) Then
                  Set fso = CreateObject("Scripting.FileSystemObject")
                  Set f = fso.GetFile(filename)
                  filesize = f.size
        End if
         ' INFO "filename is " & filename & " size is " & filesize
          If (filesize   1500000) Then
           Defect_Validation = "File " & filename & " is too big "
               Exit Function
            End If
End Function

Hook Submitter:
Francois Salazar


developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into Rational software on developerWorks

ArticleTitle=Restricting attachment size