This topic is locked

After Records Deleted Event

3/2/2014 2:24:04 AM
ASPRunnerPro General questions
lefty author

I have event for before and after records deleted . The way my project is setup I have to delete one record at a time for the before and after events to happen . I want to use after group of records deleted to do all events in one shot but the option for after group of records deleted does not support the same functions as after one record is deleted.

Such as update record in another table and send email to each individual email value. Any suggestions?
Asprunner 8.0 but have had this problem with all versions.
Function records_deleted does not cut it as that is just a count.? AfteraMassDelete can use the same as after record deleted. Never has worked for me. Tried a loop and delete happens and no events get executed.
basically I want to use deleted_values in the after mass delete.? Without having to click on each record and execute one at a time.

Sergey Kornilov admin 3/2/2014

Here is what you can do.

  1. In each BeforeDelete event save the ID of the record being deleted in session variable. This session variable needs to be an Array or a Dictionary object so it can store multiple IDs. Instead of IDs you can store some other info that might be relevant to your task.
  2. In AfterMassDelete event go through this list and send as many emails as the number of items in this Array.
  3. Remove all items from this array after all emails are sent.

lefty author 4/2/2014

Just got a chance to work on this one.
Are you saying I can use the email script in after mass delete and also update all the records in another table after mass delete. I having a hard time figuring where to put the code to save either an array code or use session (ID) 's I need all the vaules saved in a session ID as they are all being emailed.. My code is below.
Before Record Deleted. I am using a template to send a record to each user.
If deleted_values("fldpts1") > 0 Then
' load email template '

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.OpenTextFile(Server.MapPath("results_form2014.htm"))

email_message = wfile.ReadAll

wfile.close

Set wfile=nothing

Set fs=nothing

' replace variables '

email_message = Replace(email_message,"##flddate##",deleted_values("flddate"))

email_message = Replace(email_message,"##fldround##",deleted_values("fldround"))

email_message = Replace(email_message,"##fldfirst##",deleted_values("fldfirst"))

email_message = Replace(email_message,"##fldlast##",deleted_values("fldlast"))

email_message = Replace(email_message,"##start_quota##",deleted_values("start_quota"))

email_message = Replace(email_message,"##fldpts1##",deleted_values("fldpts1"))

email_message = Replace(email_message,"##next_quota##",deleted_values("next_quota"))

email_message = Replace(email_message,"##adj1##",deleted_values("adj1"))

email_message = Replace(email_message,"##cuppts##",deleted_values("cuppts"))

email_message = Replace(email_message,"##totalpoints##",deleted_values("totalpoints"))

' send HTML email '

set params = CreateObject("Scripting.Dictionary")

params("to")=deleted_values("fldemail")

params("subject")="Whitney Group Results"

params("htmlbody")=email_message

params("charset")="UTF-8"

runner_mail(params)
else

end if
Beforedelete=True
And after record deleted : I am updating multiple tables and a Temporary table for Rank.. So this is a little complicated for me. I use it know and delete one record at a time : BUT IT WOULD BE nice to select all records and the above and below would work?????????????????__
If deleted_values("fldpts1") > 0 Then

' Place event code here.

' Use "Add Action" button to add code snippets.
dal.Table("Players").Param("fldlast")=deleted_values("fldlast")
dal.Table("Players").Value("current_quota")=deleted_values("next_quota")
dal.Table("Players").Update()
'** Insert a record into another table update Archive ****

set dal_table=dal.Table("Archive")

dal_table.start_quota=deleted_values("start_quota")

dal_table.fldlast=deleted_values("fldlast")

dal_table.fldfirst=deleted_values("fldfirst")

dal_table.flddate=deleted_values("flddate")

dal_table.adj1=deleted_values("adj1")

dal_table.winner=deleted_values("winner")

dal_table.fldpts1=deleted_values("fldpts1")

dal_table.next_quota=deleted_values("next_quota")

dal_table.updown1=deleted_values("updown1")

dal_table.fldrandom=deleted_values("fldseed")

dal_table.cuppts=deleted_values("cuppts")

dal_table.fldpd=deleted_values("fldpd")

dal_table.Add()

' **end update Archive***
'**update cup points ****

If deleted_values("winner")= 1 Or deleted_values("winner") = 2 Or deleted_values("winner")= 3 Then
'** Check if specific record exists ****

strSQLExists = "select * from Cup Where fldlast = '" & deleted_values("fldlast") & "' "
set rsExists = CreateObject("ADODB.Recordset")

rsExists.Open strSQLExists, dbConnection
if not rsExists.eof then
' if record exists update cup points to player

sql="update Cup set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & " ) Where fldlast IN (Select fldlast from Cup where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
sql="update Cup set LastUpdated= '" & deleted_values("flddate") & "' Where fldlast IN (Select fldlast from Cup where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
sql="update Players set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & ") Where fldlast IN (Select fldlast from Players where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
else
'** Insert Player into cup if don't exist yet with points ****
set dal_table=dal.Table("Cup")

dal_table.cuppts=deleted_values("cuppts")

dal_table.fldlast=deleted_values("fldlast")

dal_table.LastUpdated=deleted_values("flddate")

dal_table.Add()
sql="update Players set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & ") Where fldlast IN (Select fldlast from Players where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
end if

rsExists.Close : set rsExists = Nothing
Else

End If
Else

End If
If I use session I would have to put each value/pair in a session variable before delete and after record deleted I would have to do the same. I need some code start here to accomplish this.
I know how to save session variables and then use them later but this is too involved . and would not know how to call each one after each record is deleted and send it to the each template variable I guess a nice array script in vbscrpt can do it . Just need some direction. Thanks.

G
gonzalosb 4/18/2014

first try each code by separated, make sure it works how you want it, doing what you expect from.
after that try to convene all the codes in one, for example.
instead of



If email

else

end if
if set dall table

else

end if


some ELSE you have on your code don do anything
you should do



If email
if set dall table
END IF

END IF


and not do


else

end if
else

end if


it should end with


end if

end if


Remember to group all IF toogeder first and all End IF in one ending group, for example using your code (only as example because i didn't try the code if works or not) and compare with your original and you can see what i'm tallking about.



‘1****

If deleted_values("fldpts1") > 0 Then
' load email template '

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.OpenTextFile(Server.MapPath("results_form2014.htm"))

email_message = wfile.ReadAll

wfile.close

Set wfile=nothing

Set fs=nothing

' replace variables '

email_message = Replace(email_message,"##flddate##",deleted_values("flddate"))

email_message = Replace(email_message,"##fldround##",deleted_values("fldround"))

email_message = Replace(email_message,"##fldfirst##",deleted_values("fldfirst"))

email_message = Replace(email_message,"##fldlast##",deleted_values("fldlast"))

email_message = Replace(email_message,"##start_quota##",deleted_values("start_quota"))

email_message = Replace(email_message,"##fldpts1##",deleted_values("fldpts1"))

email_message = Replace(email_message,"##next_quota##",deleted_values("next_quota"))

email_message = Replace(email_message,"##adj1##",deleted_values("adj1"))

email_message = Replace(email_message,"##cuppts##",deleted_values("cuppts"))

email_message = Replace(email_message,"##totalpoints##",deleted_values("totalpoints"))

' send HTML email '

set params = CreateObject("Scripting.Dictionary")

params("to")=deleted_values("fldemail")

params("subject")="Whitney Group Results"

params("htmlbody")=email_message

params("charset")="UTF-8"

runner_mail(params)
‘2****

If deleted_values("fldpts1") > 0 Then
dal.Table("Players").Param("fldlast")=deleted_values("fldlast")
dal.Table("Players").Value("current_quota")=deleted_values("next_quota")
dal.Table("Players").Update()
set dal_table=dal.Table("Archive")

dal_table.start_quota=deleted_values("start_quota")

dal_table.fldlast=deleted_values("fldlast")

dal_table.fldfirst=deleted_values("fldfirst")

dal_table.flddate=deleted_values("flddate")

dal_table.adj1=deleted_values("adj1")

dal_table.winner=deleted_values("winner")

dal_table.fldpts1=deleted_values("fldpts1")

dal_table.next_quota=deleted_values("next_quota")

dal_table.updown1=deleted_values("updown1")

dal_table.fldrandom=deleted_values("fldseed")

dal_table.cuppts=deleted_values("cuppts")

dal_table.fldpd=deleted_values("fldpd")

dal_table.Add()
‘3****

If deleted_values("winner")= 1 Or deleted_values("winner") = 2 Or deleted_values("winner")= 3 Then
strSQLExists = "select * from Cup Where fldlast = '" & deleted_values("fldlast") & "' "
set rsExists = CreateObject("ADODB.Recordset")

rsExists.Open strSQLExists, dbConnection
‘4*****

if not rsExists.eof then
sql="update Cup set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & " ) Where fldlast IN (Select fldlast from Cup where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
sql="update Cup set LastUpdated= '" & deleted_values("flddate") & "' Where fldlast IN (Select fldlast from Cup where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
sql="update Players set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & ") Where fldlast IN (Select fldlast from Players where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
else
set dal_table=dal.Table("Cup")

dal_table.cuppts=deleted_values("cuppts")

dal_table.fldlast=deleted_values("fldlast")

dal_table.LastUpdated=deleted_values("flddate")

dal_table.Add()
sql="update Players set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & ") Where fldlast IN (Select fldlast from Players where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
rsExists.Close : set rsExists = Nothing
‘1

END IF

‘2

END IF

‘3

END IF

‘4

END IF
lefty author 4/19/2014



first try each code by separated, make sure it works how you want it, doing what you expect from.
after that try to convene all the codes in one, for example.
instead of



If email

else

end if
if set dall table

else

end if


some ELSE you have on your code don do anything
you should do



If email
if set dall table
END IF

END IF


and not do


else

end if
else

end if


it should end with


end if

end if


Remember to group all IF toogeder first and all End IF in one ending group, for example using your code (only as example because i didn't try the code if works or not) and compare with your original and you can see what i'm tallking about.



'1****

If deleted_values("fldpts1") > 0 Then
' load email template '

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.OpenTextFile(Server.MapPath("results_form2014.htm"))

email_message = wfile.ReadAll

wfile.close

Set wfile=nothing

Set fs=nothing

' replace variables '

email_message = Replace(email_message,"##flddate##",deleted_values("flddate"))

email_message = Replace(email_message,"##fldround##",deleted_values("fldround"))

email_message = Replace(email_message,"##fldfirst##",deleted_values("fldfirst"))

email_message = Replace(email_message,"##fldlast##",deleted_values("fldlast"))

email_message = Replace(email_message,"##start_quota##",deleted_values("start_quota"))

email_message = Replace(email_message,"##fldpts1##",deleted_values("fldpts1"))

email_message = Replace(email_message,"##next_quota##",deleted_values("next_quota"))

email_message = Replace(email_message,"##adj1##",deleted_values("adj1"))

email_message = Replace(email_message,"##cuppts##",deleted_values("cuppts"))

email_message = Replace(email_message,"##totalpoints##",deleted_values("totalpoints"))

' send HTML email '

set params = CreateObject("Scripting.Dictionary")

params("to")=deleted_values("fldemail")

params("subject")="Whitney Group Results"

params("htmlbody")=email_message

params("charset")="UTF-8"

runner_mail(params)
'2****

If deleted_values("fldpts1") > 0 Then
dal.Table("Players").Param("fldlast")=deleted_values("fldlast")
dal.Table("Players").Value("current_quota")=deleted_values("next_quota")
dal.Table("Players").Update()
set dal_table=dal.Table("Archive")

dal_table.start_quota=deleted_values("start_quota")

dal_table.fldlast=deleted_values("fldlast")

dal_table.fldfirst=deleted_values("fldfirst")

dal_table.flddate=deleted_values("flddate")

dal_table.adj1=deleted_values("adj1")

dal_table.winner=deleted_values("winner")

dal_table.fldpts1=deleted_values("fldpts1")

dal_table.next_quota=deleted_values("next_quota")

dal_table.updown1=deleted_values("updown1")

dal_table.fldrandom=deleted_values("fldseed")

dal_table.cuppts=deleted_values("cuppts")

dal_table.fldpd=deleted_values("fldpd")

dal_table.Add()
'3****

If deleted_values("winner")= 1 Or deleted_values("winner") = 2 Or deleted_values("winner")= 3 Then
strSQLExists = "select * from Cup Where fldlast = '" & deleted_values("fldlast") & "' "
set rsExists = CreateObject("ADODB.Recordset")

rsExists.Open strSQLExists, dbConnection
'4*****

if not rsExists.eof then
sql="update Cup set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & " ) Where fldlast IN (Select fldlast from Cup where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
sql="update Cup set LastUpdated= '" & deleted_values("flddate") & "' Where fldlast IN (Select fldlast from Cup where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
sql="update Players set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & ") Where fldlast IN (Select fldlast from Players where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
else
set dal_table=dal.Table("Cup")

dal_table.cuppts=deleted_values("cuppts")

dal_table.fldlast=deleted_values("fldlast")

dal_table.LastUpdated=deleted_values("flddate")

dal_table.Add()
sql="update Players set cuppts=(IIF(ISNULL(cuppts),0,cuppts) + " & deleted_values("cuppts") & ") Where fldlast IN (Select fldlast from Players where fldlast = '" & deleted_values("fldlast") & "')"

customQuery(sql)
rsExists.Close : set rsExists = Nothing
'1

END IF

'2

END IF

'3

END IF

'4

END IF




Thanks for the help ,
Only thing is really should have taken the else out here for what I really need and that is to send mass email to all selected records after delete instead of one at a time . So your suggestion in a way is correct , but your example 1 then 2 then 3 etc... I could see that I could assign a field value to do this but the table is like a temp table it changes every week and all records get deleted weekly . So Not sure how I can loop through each record when I just select delete all and 1. update tables and 2. send templated email record to each user. Now each user gets different values . As far as the If else end statement . Asprunner throws an error if I do not enclose all checks for IF . That is just the way their syntax checker works . Probably can make it more condensed but it does work as I delete one record at a time and updates table and send email . what I want to do is check all records hit delete all and send each row to the respectie email user , as each row belongs to one user. Will try some coding with your ideas though , again thanks for the effort, appreciate it.
I was thinking I can save each field value in a session before process event . Would be a lot of coding though . Then loop through all the records . I just don't know where to put in which event the code for updating the tables and sending email , As after mass delete does not support those functions. That is where I am stuck. As least that is what the manual shows .

G
gonzalosb 4/21/2014

i come up with this solution for you, tell me what you think.

  1. create a new button next to DELETE SELECTED button on top of the page
  2. add the following code to SERVER event on the new button



DoAssignment record, button.getNextSelectedRecord()
' load email template '

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.OpenTextFile(Server.MapPath("results_form2014.htm"))

email_message = wfile.ReadAll

wfile.close

Set wfile=nothing

Set fs=nothing

' replace variables '

email_message = Replace(email_message,"##flddate##", values ("flddate"))

email_message = Replace(email_message,"##fldround##", values ("fldround"))

email_message = Replace(email_message,"##fldfirst##",values ("fldfirst"))

email_message = Replace(email_message,"##fldlast##", values ("fldlast"))

email_message = Replace(email_message,"##start_quota##", values ("start_quota"))

email_message = Replace(email_message,"##fldpts1##", values ("fldpts1"))

email_message = Replace(email_message,"##next_quota##", values ("next_quota"))

email_message = Replace(email_message,"##adj1##", values ("adj1"))

email_message = Replace(email_message,"##cuppts##", values ("cuppts"))

email_message = Replace(email_message,"##totalpoints##", values ("totalpoints"))

' send HTML email '

set params = CreateObject("Scripting.Dictionary")

params("to")= values ("fldemail")

params("subject")="Whitney Group Results"

params("htmlbody")=email_message

params("charset")="UTF-8"

runner_mail(params)
sql = "update Archive set joinedfield=" & values("fromoriginaldfield")

dbConnection.Execute sql
Delete from ThisTable where IDField=" & values("ID")
DoAssignment record, button.getNextSelectedRecord()


First it will send an email with the field information before the update to the database

Then will update the second table that i belive you called " Archive "

and finish deleting the existing record base on the record ID
i replace " deleted_values " for "values" because will send the email before delete.

i also replase the DAL.TABLE functions with DBConnection (update and delete) witch works better for me.
on " params("to")= values ("fldemail") " replace the value with the one on the original table
" DoAssignment record, button.getNextSelectedRecord()" will redo the function for every selected record.

if you add the button to apear on each row instead of top of the page, you need to replace " getNextSelectedRecord() " with " getCurrentRecord() "
let me know if works for you

lefty author 4/25/2014



i come up with this solution for you, tell me what you think.

  1. create a new button next to DELETE SELECTED button on top of the page
  2. add the following code to SERVER event on the new button



DoAssignment record, button.getNextSelectedRecord()
' load email template '

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.OpenTextFile(Server.MapPath("results_form2014.htm"))

email_message = wfile.ReadAll

wfile.close

Set wfile=nothing

Set fs=nothing

' replace variables '

email_message = Replace(email_message,"##flddate##", values ("flddate"))

email_message = Replace(email_message,"##fldround##", values ("fldround"))

email_message = Replace(email_message,"##fldfirst##",values ("fldfirst"))

email_message = Replace(email_message,"##fldlast##", values ("fldlast"))

email_message = Replace(email_message,"##start_quota##", values ("start_quota"))

email_message = Replace(email_message,"##fldpts1##", values ("fldpts1"))

email_message = Replace(email_message,"##next_quota##", values ("next_quota"))

email_message = Replace(email_message,"##adj1##", values ("adj1"))

email_message = Replace(email_message,"##cuppts##", values ("cuppts"))

email_message = Replace(email_message,"##totalpoints##", values ("totalpoints"))

' send HTML email '

set params = CreateObject("Scripting.Dictionary")

params("to")= values ("fldemail")

params("subject")="Whitney Group Results"

params("htmlbody")=email_message

params("charset")="UTF-8"

runner_mail(params)
sql = "update Archive set joinedfield=" & values("fromoriginaldfield")

dbConnection.Execute sql
Delete from ThisTable where IDField=" & values("ID")
DoAssignment record, button.getNextSelectedRecord()


First it will send an email with the field information before the update to the database

Then will update the second table that i belive you called " Archive "

and finish deleting the existing record base on the record ID
i replace " deleted_values " for "values" because will send the email before delete.

i also replase the DAL.TABLE functions with DBConnection (update and delete) witch works better for me.
on " params("to")= values ("fldemail") " replace the value with the one on the original table
" DoAssignment record, button.getNextSelectedRecord()" will redo the function for every selected record.

if you add the button to apear on each row instead of top of the page, you need to replace " getNextSelectedRecord() " with " getCurrentRecord() "
let me know if works for you


Okay this does make it easier since it is a button an on server event. I will try this . I really appreciate your thinking on this one as I was trying to go the events way and was just no coming up with anything. Looking at the code looks right . I see now it will just auto loop to next selected record and delete and ID is an autonumber key so that works. Nice! i will test this weekend and let you know and again thanks for the code. Will have to reciprocate this one day.

G
gonzalosb 4/29/2014

Glad i can help you John.

let us know how it works and your end result.