Restricting large attachments in Quality Center
Once your Quality Center users discover that they can add attachments to defects (and test cases, and test sets etc etc), your storage requirements increase dramatically. Here is a neat way to prevent your users from attaching files over a certain size anywhere in Quality Center.
A client had a requirement to reduce the use of QC attachment storage as a lot of users are using up a lot of space unnecessarily. In one instance I found over 80GB of file space taken up with a 100MB file endlessly repeated. The attachment was on a “template” test and the users had duplicated it whenever they copied and pasted the “template”
I had to get this working today so investigated the attachment object and found it has some hooks so we could get it working quite simply.
The “Attachment” object available in the sub can give you access to the “CR_ENTITY” it is linked to. This gives us ALL the areas where a user can create an attachment. From there it was simply trial and error until I had the attachment record (attRec) described correctly for each “CR_ENTITY”.
The code goes directly into the QC workflow Common scripts area and replaces the existing Sub “Attachment_New”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | Sub Attachment_New(Attachment) 'Use ActiveModule and ActiveDialogName to get the current context. On Error Resume Next 'Remove new attachment if file size is too big If Attachment.Type = 1 then 'Attachment is of type TDATT_FILE - a file. MaxFileSize = 3145728 'Set the maximum attachment size in Bytes <<- 3mb is our limit! If Attachment.FileSize > MaxFileSize then Select Case Attachment.Field("CR_ENTITY") 'Requirement Case "REQ" Set attRec = ReqFactory.Item(Attachment.Field("CR_KEY_1")) 'TestPlan Case "ALL_LISTS" 'Folder Set attRec = TreeManager.NodeByID(Attachment.Field("CR_KEY_1")) msgbox attRec.ID Case "TEST" ' Test Set attRec = TestFactory.Item(Attachment.Field("CR_KEY_1")) Case "DESSTEPS" 'Test step Set attTest = TestFactory.Item(Test_Fields("DS_TEST_ID").Value) Set attRec = attTest.DesignStepFactory.Item(Attachment.Field("CR_KEY_1")) 'TestLab Case "CYCL_FOLD" 'Folder Set attRec = TestSetTreeManager.NodeById(Attachment.Field("CR_KEY_1")) Case "CYCLE" 'Test Set Set attRec = TestSetFactory.Item(Attachment.Field("CR_KEY_1")) Case "TESTCYCL" 'TestInstance Set attRec = TSTestFactory.Item(Attachment.Field("CR_KEY_1")) Case "RUN" 'Run Set attRec = RunFactory.Item(Attachment.Field("CR_KEY_1")) Case "STEP" 'Run Step Set attRun = RunFactory.Item(Step_Fields("ST_RUN_ID").Value) Set attRec = attRun.StepFactory.Item(Attachment.Field("CR_KEY_1")) 'Defects Case "BUG" Set attRec = BugFactory.Item(Attachment.Field("CR_KEY_1")) End Select set AttFac = attRec.Attachments Msgbox "Please exit this record and refresh the QC page. The file: " & vbLF & _ Attachment.Name & vbLf & " has been removed as it exceeds the required file size of 3mb." AttFac.RemoveItem(Attachment.ID) End If End If On Error GoTo 0 End Sub |
Related posts:
- HP Software Trial License Periods HP software tools all have have different trial licensing periods....
- Querying the Quality Center Database Sometimes the reports available from Quality Center don’t quite give...
- Querying Quality Center user roles Quality Center stores the user/role relationship in a strange way...
- Restore old License Usage stats after upgrading Quality Center Following the upgrade of Quality Center from v.9 to v.10,...
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
April 28th, 2010 at 4:32 am
The problem is the Attachment_New method does not get invoked when CREATING a defect and adding an attachment…. only when working with an existing defect and adding an attachment. HP has been notified of this BUG, but as of QC 9.2 they still have not fixed it.
May 24th, 2010 at 4:32 pm
I found that when creating a Defect and adding an attachment QC does something novel.
In order to attach an item QC requires an entity to exist. In this case, on Bug_New we use “actAttachFile” and before actually populating the Defect with field values it creates a temporary bug entity and attaches the attachment. This temporary entity is inaccessable. Then when you hit post it updates the rest of the fields.
The script above cannot work with this as there is no visible ID is can use to check/change attachements.
I have not looked into what happens when you cancel after adding an attachment on bug new, but I assume there is a roll back function that gets called by QC.