We have a requirement to reduce the use of our 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 [img]/images/graemlins/confused.gif[/img]
The attachment was on a "template" test and the users had duplicated it whenever they copied and pasted the "template" [img]/images/graemlins/smirk.gif[/img]
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".
<font class="small">Code:</font><hr /><pre>
'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")
Set attRec = ReqFactory.Item(Attachment.Field("CR_KEY_1"))
Case "ALL_LISTS" 'Folder
Set attRec = TreeManager.NodeByID(Attachment.Field("CR_KEY_1"))
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("C R_KEY_1"))
Case "CYCL_FOLD" 'Folder
Set attRec = TestSetTreeManager.NodeById(Attachment.Field("CR_K EY_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 "))
Set attRec = BugFactory.Item(Attachment.Field("CR_KEY_1"))
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."
On Error GoTo 0
While I have been working for Businesses that are Vendor partners with HP, IBM and Microsoft, my opinions and advice is my own.
The solutions provided are either sourced from my own scripting libraries or from a quick Google Search.
Unfortunately in QC 9.2 there is a bug in regards to the Attachment_New method. It only executes when you update an existing Defect. If you are adding a new Defect it does not execute the Attachment_New method even though you are attaching a file.
HP is aware of this.. and may fix in a later patch.