Contents

 
Home
ASPRunner Professional 7.0 manual
Prev Page Next Page
 
 

Email selected records

 

To send an email with several selected records on the list page you need to create new custom button.

yellowbulbNote: Change the values listed in red to match your specific needs.

1. Proceed to the Visual Editor page.

2. Create the custom button Update selected and add the following code

to the Server tab:

dim arr,i

currentTable = "TableName"

 

if keys.Count>0 then

  body=""

  set rmail=CreateDictionary()

  for i=0 to keys.Count-1

     arr=split(keys.Item(i)("FieldName"),"&")

    if asp_count(arr)>=0 then

        set arr2=CreateDictionary()

        arr2("FieldName")=asp_urldecode(arr(0))

        where = KeyWhere(arr2,"")

        set data = dal.Table(currentTable).Query(where,"")

        body=body & "OrderID: " & data("OrderID")  & vbcrlf

        body=body & "Customer: " & data("CustomerID") & vbcrlf

        body=body & "Employee: " & data("EmployeeID") & vbcrlf _

           & "-------------------" & vbcrlf & vbcrlf

        data.close

        set data=nothing

    end if

  next

 

' send the email

  rmail("to")="test@test.com"

  rmail("subject")="Sample subject"

  rmail("body")=body

  set arr = runner_mail(rmail)

  result("txt") = "Emails were sent."

 

  ' if error happened print a message on the web page

  if arr("mailed") then

     errmsg = "Error happened: <br>"

     errmsg = errmsg & "File: " & arr("source") & "<br>"

     errmsg = errmsg & "Line: " & arr("number") & "<br>"

     errmsg = errmsg & "Description: " & arr("description") & "<br>"

     result("txt") = errmsg

  end if

end if

and to the Client After tab:

var message = result["txt"];

ctrl.setMessage(message);

The Client Before tab should be blank (delete sample code there if any).

Sample email message:

OrderID: 10249

Customer: TRADH

Employee: 6

-------------------

OrderID: 10251

Customer: VICTE

Employee: 3

-------------------

OrderID: 10253

Customer: HANAR

Employee: 3

-------------------

yellowbulbNote: How to send email to the current logged user.

Instead of hardcoded email address you can send it to the current logged user. If you use email address as a username use the following:

email=Session("UserID")

If email address is stored in another field of users table you need to save it to the session variable in AfterSuccessfulLogin event:

Session("email")=data("email")

Then in BeforeProcess event code use the following:

email=Session("email")

Converted from CHM to HTML with chm2web Standard 2.85 (unicode)