See below for an example of how to create a workflow to send defect email based on a status change. In the below example if the defect status is changed to ''Development'' then an email is sent to all users in the user group ''TDAdmin'' and another email address ''fake@email.com'' is copied on the message. In the below example a new sub routine would need to be created called ''SendDefectMail'' this would be placed in the defect workflow outside of the other sub routines. Then this sub is called in the already existing Bug_AfterPost.
Note: This is just an example, this code will need to be modified to fit your specific needs. I would suggest to implement this in a test project and test before implementing in production.
Where the code goes will really depend on what set of circumstances that you want the email to be triggered under. In the example I placed the code into the Bug After Post section because I wanted the event to be triggered when a defect is modified and saved and meets certain criteria.
Another place that the code could be placed is in the Bug field change(this would send the email as soon as the field is changed to a certain value even if the defect is not saved).
It could also be put into bug new(then it would only send the email if the condition is met and it is a new defect being created, if the field was changed on an existing defect then it would not be sent).
Sub SendDefectMail (iObjectId, strTo, strCc, strSubject, strComment)
On Error Resume Next
Dim objBugFactory, objBug
Set objBugFactory = TDConnection.BugFactory
Set objBug = objBugFactory.Item(iObjectId)
objBug.Mail strTo, strCc, 2, strSubject, strComment
Set objBug = Nothing
Set objBugFactory = Nothing
PrintError ''SendDefect''
On Error GoTo 0
End Sub
Sub Bug_AfterPost
On Error Resume Next
If bug_fields(''BG_Status'').value = ''Development'' Then
strSubject = ''Defect Change Notification'' & _
'' for project: '' & TDConnection.ProjectName & _
'' in domain: '' & TDConnection.DomainName
strComment = ''The status of this defect has been changed to Development''
SendDefectMail Bug_Fields(''BG_BUG_ID'').Value, _
''[TDAdmin]'', ''fake@email.com'', _
strSubject, StrComment
End If
On Error GoTo 0
End Sub