Applies to:
HP ALM Workflow, HP QC Workflow
Issue:
The customer wants to send a notification email and include only a subset of the attachements. As you could imagine, a development object or requirement can aqcuire many attachments over a period of time and most companies have size limits on their email inboxes.
Solution:
In the example, strFilterType allows the user to filter through all attachments and could attach only the attachments that have <SOMETHING> in their name. When calling this procedure the user can pass "Transport" to strFilterType and only the attachments with "Transport" in their name will be attached to the email.
'***************************************************************************** '----------------------------------------------------------------------------- ' ' Procedure: USER_Template_AttachFileAndSendMail ' ' Purpose: Send a simple email by passing the To, CC, Subject, and Comment as ' arguments and include an specific set of attachments. strFilterType ' is the filter we use to do an instring on the names of the ' attachments. ' ' Initially Coded By: Chris Carpenter, Principal HP ALM Consultant ' Bienabee Technologies, LLC ' ' Date: 5/21/2014 ' '----------------------------------------------------------------------------- '***************************************************************************** Sub USER_Template_AttachFileAndSendMail(strTo, strCC, strSubject, strComment, strFilterType) Dim objTDC, objAttachFact, objAttachment, objAttachment2, objAttachList Dim objReqFact, strReqId, objReq, objAttachmentList ' Set our connection Set objTDC = TDConnection ' Instantiate the Requirement Factory Set objReqFact = objTDC.ReqFactory ' Whichever requirement we are working with, grab its ID strReqId = Req_Fields("RQ_REQ_ID").Value ' Use the requirement facotry of that particular requirement Set objReq = objReqFact.Item(strReqId) ' Initialize the Attachments factory of said requirement Set objAttachFact = objReq.Attachments ' Create a list of all the attachments from the attachment factory Set objAttachList = objAttachFact.NewList("") ' We need to determine how many attachments fit our filter criteria ' loop through the list and count how many we have. For Each objAttachment In objAttachList If Instr(objAttachment.ServerFileName, strFilterType) then j = j + 1 End If Next ' We need to specify how big the array is depending on how many attachments ' we want to email. If j < 1 Then 'dont declare the array Else 'Declare the array but subtract 1 from j since the array is a 0 index ReDim objAttachmentList(j - 1) End If ' Now that we have or have not declared the array, its time to populate it ' based on the attachments that have a certain string in their name. For Each objAttachment2 In objAttachList If instr(objAttachment2.ServerFileName,strFilterType) Then objAttachmentList(i) = objAttachment2.ServerFileName i = i + 1 End If Next objTDC.SendMail strTo, strCC, strSubject, strComment, objAttachmentList End Sub