This topic is locked
[SOLVED]

 Send an email based on a field value

7/23/2010 1:38:03 AM
ASPRunnerPro General questions
W
Wallaroo author

Hi
I am using ASP Runner6.2 and want to configure a table to send record data in an email (AfterEdit function) based on a field value. For example, once a record has been updated in Table A, I want to send an email containing the record data but only if the field "Status" equals "Approved". If the field "Status" contains any other value then an email is not sent.
I'm new to this coding stuff so any help would be greatly appreciated!

A
ann 7/23/2010

Hi,
use After record updated event on the Events tab and predefined action Save email with new data (Add action button on the Events tab).

Here is a sample:

if values("Status")= "Approved" then

'send email

end if
W
Wallaroo author 7/23/2010



Thanks Ann -that worked a treat! Now following on from that, can you help me with this query?
how would I send an email to one addressee if the value = "A", but send it to two different addressees if value ="B".
Here is my current code:-
if values("LeaveApproved")= "Approved" then

Dim dkeys, tmpDict, msg, n

msg ="This is an auto generated email to advise of your Leave Application status." & vbcrlf

msg = msg & "" & vbcrlf

msg = msg & "ID: " & dict("ID")& vbcrlf

msg = msg & "Name: " & dict("Name")& vbcrlf

msg = msg & "Staff No: " & dict("StaffNo")& vbcrlf

msg = msg & "Port: " & dict("Port")& vbcrlf

msg = msg & "Leave Start Date: " &format_shortdate(db2time(dict("LeaveStartDate"))) & vbcrlf

msg = msg & "Leave End Date: " &format_shortdate(db2time(dict("LeaveEndDate"))) & vbcrlf

msg = msg & "Leave Type: " & dict("LeaveType")& vbcrlf

msg = msg & "Leave Status: " & dict("LeaveApproved")& vbcrlf

msg = msg & "Approved By: " & dict("ApprovedBy")& vbcrlf

msg = msg & "Approved Date: " &format_shortdate(db2time(dict("ApprovedDate")))& vbcrlf

msg = msg & "" & vbcrlf

msg = msg & "Should you have any queries regarding this email, please direct them to your Manager."
set tmpDict = CreateObject("Scripting.Dictionary")

tmpDict("to")=dict("Email")

tmpDict("cc")=dict("ManagerEmail")

tmpDict("subject")="LEAVE APPLICATION STATUS"

tmpDict("body")=msg

set ret=runner_mail(tmpDict)

if not ret("mailed") then

response.write ret("message")
end if

end if
This works fine, but I now want to amend the code so that the email addressee shown as "CC" does notget an email if the value in the field "LeaveApproved" = "Declined".
Many Thanks
use After record updated event on the Events tab and predefined action Save email with new data (Add action button on the Events tab).

Here is a sample:

if values("Status")= "Approved" then

'send email

end if


A
ann 7/26/2010

Hi,
just add the similar code:

if values("LeaveApproved")= "Declined" then

...

tmpDict("to")=dict("Email")

tmpDict("subject")="LEAVE APPLICATION STATUS"

...

end if