IBM Support

How to write a Base Action Perl hook in Rational ClearQuest to limit size of a file being attached to a record

Question & Answer


Question

How do you write a Base Action Perl hook in IBM Rational ClearQuest to limit the size of a file being attached to a record?

Cause

This is required to limit ClearQuest users to attach big size files to the records.

Answer

This Base action Perl hook code will not allow to attach a file which is more than 200 bytes in size. You can modify this limit in the hook code as per your requirements.

PROCEDURE:

 
Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

 
  1. Login to ClearQuest Designer with the role admin
     
  2. Click on Record Types > Navigate to the Record Type (For example Defect) > States And Actions > Actions
     
  3. Right click on Actions and click on New Action. This will open a new window where you can Add a new Action
     
  4. Give the Action Name and select Type as BASE. Click on Next and select all the states using Select All
     
  5. Click Next and then Finish
     
  6. You will see this newly created Action under the Actions
     
  7. Double click on it, this will show all the Actions in right side panel
     
  8. Select the row of newly created action and click on the cell under the Validation column. It will open a drop down button, click on it and select SCRIPTS -> Add Perl Script
     
  9. This will Open the Validation Subroutine in Perl Script Editor

    Example:

    sub Defect_Validation {
    my($actionname, $actiontype) = @_;
    my $result;
    # $actionname as string scalar
    # $actiontype as long scalar
    # $result as string scalar
    # action is Assign
    # record type name is Defect
    # Return a non-empty string explaining why the action cannot commit
    # with its current values. If it is valid, return an empty string.
    # Example:
    #    my $value_info = $entity->GetFieldValue("some field");
    #    if (length($value_info->GetValue()) < 10) {
    #        $result = "Must be at least 10 chars long";
    #    }
    return $result;
    }
  10. Place the following code within this subroutine

    # This code will Not allow to attach a file which more than 200 bytes
    $session = $entity->GetSession();
    $attachfields = $entity->GetAttachmentFields();
    $attachfield1 = $attachfields->Item(0);
    $attachments = $attachfield1->GetAttachments();
    $numattachments = $attachments->Count();

    for ($x = 0 ; $x < $numattachments ; $x++)
    {
      $attachment = $attachments->Item($x);
       $description = $attachment->GetDescription();    
       $filename = $attachment->GetFileName();
      $filesize1 = -s $filename;
    If ($filesize1 > 200)
    {
    $result = "Please do not attach big files. File name $filename - size is $filesize1";
    }
    }
    #######################################

     
  11. Save the work and perform Validation and check for errors
     
  12. If no errors, perform a Test Work
     
  13. Verify in the Test Database, if it is working as expected
     
  14. Once verified in the Test Database, CheckIn the Schema and Upgrade the Database

[{"Product":{"code":"SSSH5A","label":"Rational ClearQuest"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Designer - Hooks","Platform":[{"code":"PF033","label":"Windows"}],"Version":"8.0.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
21 March 2021

UID

swg21666054