This topic is locked

Email if Field Changes

2/18/2007 3:20:34 PM
ASPRunnerPro General questions
D
DNuccio author

I have a field called ASSIGNED TO. when on the edit page if someone changes the assigned to field from what was already there to something new (even if the field was originally null) what is the IF statement I need to use to send a simple email only at the time of this field value change? This field is a dropdown lookup field.

C
clig 2/18/2007

I have a field called ASSIGNED TO. when on the edit page if someone changes the assigned to field from what was already there to something new (even if the field was originally null) what is the IF statement I need to use to send a simple email only at the time of this field value change? This field is a dropdown lookup field.


Sub EditOnLoad(where)
' Parameters:

' where - string with WHERE clause pointing to record to be edited

'** Custom code ****

' put your custom code here
set CN = server.CreateObject("ADODB.Connection")

CN.Open "DSN=dsn;UID=user;PWD=pass"

set rs = Server.CreateObject("ADODB.Recordset")

rs.Open "Select [ASSIGNED TO] From TableName Where ID = " & GetRequestForm("editid"), CN

Session("OldValue") = rs("ASSIGNED TO")

rs.Close
End Sub
Function BeforeEdit(dict, where)
' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Edit form represented as 'Field name'-'Field value' pair

' where - string with WHERE clause pointing to record to be edited
'** Custom code ****

' put your custom code here
Session("NewValue") = dict("ASSIGNED TO")
If Cstr(Session("NewValue")) = Cstr(Session("OldValue")) Then

Session("SendNewValue") = 0

Else

Session("SendNewValue") = 1

End If
BeforeEdit = True
' set BeforeEdit to True if you like to proceed with editing this record

' set it to False in other case
End Function
Sub AfterEdit()

'** Send simple email ****

' do not forget to setup email parameters like From, SMTP server etc

' on 'Security->User login settings' dialog

If Session("SendNewValue") = 1 Then

email=Session("Email")

message="Old Value: " & Session("OldValue") & " - New Value: " & Session("NewValue")

subject="A Field has been edited"

sendmail email, subject, message

Response.Write "Email Sent: SendNewValue: " & Session("SendNewValue")

Else

Response.Write "Old Value: " & Session("OldValue") & " - New Value: " & Session("NewValue")

End If
End Sub