If this is an exact copy of what is in your workflow customization script editor, it is not suprising you have problems.
1. You have two "Sub Bug_AfterPost" subroutines.
2. Your code to send email when the Status field changes isn't actually contained in any subroutine, so it will never execute.
3. In that code (that isn't in a subroutine) to send an email when Status changes you start an IF-THEN block, but the End If statement seems to be tacked on at the bottom, after the code for three subroutines (Bug_AfterPost and Bug_CanPost and Bug_FieldChange). That isn't even valid syntax.
First correction:
Delete this from your workflow script editor.
Sub Bug_AfterPost On Error Resume Next On Error GoTo 0 End Sub
Second correct:
Delete this from your workflow script editor:
Dim strTo Dim strSubject Dim strComment If Bug_Fields("BG_STATUS").IsModified Then strTO = Bug_Fields("BG_RESPONSIBLE").Value strSubject = "Defect Status for the defect " & BUG_Fields("BG_BUG_ID").value & " Has Changed to " & BUG_Fields("BG_Status").value strComment = "Defect Status for the defect " & BUG_Fields("BG_BUG_ID").value & " Has Changed to " & BUG_Fields("BG_Status").value TDConnection.sendmail strTo, strFrom, strSubject, strComment, NULL, "HTML" Set TDConnection = nothing MsgBox "Mail Sent" 'End if
Third correction:
Delete the line I'm pointing at:
Sub Bug_FieldChange(FieldName) On Error Resume Next On Error GoTo 0 End Sub End If <<<<<<<< Delete just this line
Last correction:
Go to your remaining Bug_AfterPost subroutine, delete all the code between the Sub and the End Sub statements, and paste in this code. Make an exact copy because I changed variable names.
On Error Resume Next
Dim objBug Dim strTo Dim strCc Dim strFrom Dim strSubject Dim strComment Dim mailopt if Bug_Fields.Field("BG_RESPONSIBLE").IsModified Then set objBug = TDConnection.BugFactory.Item(Bug_Fields.Field("BG_BUG_ID").Value) strTo = Bug_Fields("BG_RESPONSIBLE").Value strCc = "" mailopt=1 'TDMAIL_ATTACHMENT strSubject="Defecto No. "& Bug_Fields.Field("BG_BUG_ID").Value & " has been reassigned" strComment=Bug_Fields.Field("BG_DEV_COMMENTS").IsNull objBug.Mail strTo ,strCc,mailopt,subject,comment MsgBox "Mail Sent" End if If Bug_Fields("BG_STATUS").IsModified Then strTo = Bug_Fields("BG_RESPONSIBLE").Value strFrom = Bug_Fields("BG_RESPONSIBLE").Value strSubject = "Defect Status for the defect " & BUG_Fields("BG_BUG_ID").value & " Has Changed to " & BUG_Fields("BG_Status").value strComment = "Defect Status for the defect " & BUG_Fields("BG_BUG_ID").value & " Has Changed to " & BUG_Fields("BG_Status").value TDConnection.sendmail strTo, strFrom, strSubject, strComment, NULL, "HTML" MsgBox "Mail Sent" End if
On Error GoTo 0
Paste it in exactly where the "..." is:
Sub Bug_AfterPost ... End Sub
Make note that if you change values through the Defect Grid display (vs. opening the Defect Details dialog) the AfterPost code won't execute until you click on a different row.