Alpha Video Training
Results 1 to 6 of 6

Thread: Email AfterUpdateRecords Problem

  1. #1
    Member
    Real Name
    Robert Neil
    Join Date
    Nov 2008
    Posts
    41

    Default Email AfterUpdateRecords Problem

    Hello,

    I have read numerous threads and I am still having a problem. I have been working on this for a few hours.

    I have an a5w page with a grid in add mode allowing people to report a safety hazard. The page works fine, it updates to the linked table and I can get an email using email_send when a new record is added.

    The problem is that I would like the reported information included in the email I receive.

    My fields are (User is not required to enter data in each):

    Safetyr_idf (Auto increment ID)
    Safetyr_typef (Selected with drop down)
    Safetyr_commentf (Free text)
    Safetyr_contactf (Free text)
    Safetyr_phonef (Free text)
    Safetyr_emailf (Free text)

    Any help would be appreciated.

    Also, is there any way to send a confirmation to the user if they entered their email or possible to the screen?

    Thanks

  2. #2
    Member
    Real Name
    Robert Neil
    Join Date
    Nov 2008
    Posts
    41

    Default Re: Email AfterUpdateRecords Problem

    Here is what I ended up with. Is there a better (more concise) way?

    Thanks...Any input would be greatly appreciated.

    *****************************************

    function AfterUpdateRecords as v (Args as P, PageVariables as P)

    with PageVariables

    'row 1

    if eval_valid("Args.DataSubmitted.R1.Dept_Idf") = .T.

    dim Dept_Id as C

    Dept_Id = Args.DataSubmitted.R1.Dept_Idf

    if Dept_Id <> "" then

    Line1=Dept_Id+crlf()

    end if

    'Row 2

    if eval_valid("Args.DataSubmitted.R1.Safetyr_Typef") = .T.

    dim Safetyr_Type as C

    Safetyr_Type = Args.DataSubmitted.R1.Safetyr_Typef

    if Safetyr_Type <> "" then

    Line2=Safetyr_Type+crlf()

    end if

    'Row 3

    if eval_valid("Args.DataSubmitted.R1.Safetyr_Commentf") = .T.

    dim Safetyr_Comment as C

    Safetyr_Comment = Args.DataSubmitted.R1.Safetyr_Commentf

    if Safetyr_Comment <> "" then

    Line3=Safetyr_Comment+crlf()

    end if

    'Row 4

    if eval_valid("Args.DataSubmitted.R1.Safetyr_Locationf") = .T.

    dim Safetyr_Location as C

    Safetyr_Location = Args.DataSubmitted.R1.Safetyr_Locationf

    if Safetyr_Location <> "" then

    Line4=Safetyr_Location+crlf()

    end if

    dim message as C

    message=Line1+Line2+Line3+Line4

    SendNOW:
    dim pm as P
    dim ps as P

    if (email_smtp_open(ps, "smtp.gmail.com", 587, "myusername", "mypassord" ,"TLS")) then
    pm.to = "mypersonalinformation"
    pm.cc = "mypersonalinformation"
    pm.from = "mypersonalinformation"
    pm.subject = "A new safety hazard has been reported"
    pm.message = message
    email_smtp_send(pm, ps)
    end if
    email_smtp_close(ps)

    end if
    end if
    end if
    end if
    end with
    end function

  3. #3
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default Re: Email AfterUpdateRecords Problem

    For situations like this where I wish to update a table, send some or all inputted information to me AND also send a duplicate to the person completing the form (or anyone for that matter), I use a dialog not a grid. The dialog's AfterValidate section gives you a lot of control.

    You don't seem to have a lot of fields here so constructing your dialog should not take a lot of time. Then in the AfterValidate, perhaps do something like this:

    dim e_to as c
    dim e_body as c
    dim e_subj as c
    e_to = youremailaddress
    e_bcc = anotheremailaddress
    e_subj = CurrentForm.Controls.subject.value
    e_body = "Hello" + crlf()
    e_body = e_body + "Here is the information just entered." + crlf(2)
    e_body = e_body + CurrentForm.Controls.Safetyr_idf.value + crlf()
    e_body = e_body + CurrentForm.Controls.Safetyr_typef.value + crlf()
    e_body = e_body + CurrentForm.Controls.Safetyr_commentf.value + crlf()
    e_body = e_body + CurrentForm.Controls.Safetyr_contactf.value + crlf()
    e_body = e_body + CurrentForm.Controls.Safetyr_phonef.value + crlf()
    e_body = e_body + CurrentForm.Controls.Safetyr_emailf.value + crlf()
    email_send(e_to,e_subj,e_body,"","",e_bcc,.F.,"","","")

    If you are entering a new record when the user keys in the information, you may want to have something like this also in the AfterValidate:

    dim tbl as p
    tbl=table.open("[pathalias.adb_path]\your table name")
    tbl.enter_begin(.T.) OR tbl.change_begin() ........ (if changing data in a table)
    tbl.Safetyr_idf = CurrentForm.Controls.Safetyr_idf.value
    tbl.Safetyr_typef = CurrentForm.Controls.Safetyr_typef.value
    tbl.Safetyr_commentf = CurrentForm.Controls.Safetyr_commentf.value
    tbl.Safetyr_contactf = CurrentForm.Controls.Safetyr_contactf.value
    tbl.Safetyr_phonef = CurrentForm.Controls.Safetyr_phonef.value
    tbl.Safetyr_emailf = CurrentForm.Controls.Satetyr_emailf.value
    tbl.enter_end(.T.) OR tbl.change_end(.T.)
    tbl.close()
    Last edited by EricN; 11-30-2008 at 10:06 PM.
    Eric

    Alpha Five Websites
    longlivepuppies.com
    socialservicenetwork.com
    -------------------------------------------------
    socialservicenetwork.org

  4. #4
    Member
    Real Name
    Robert Neil
    Join Date
    Nov 2008
    Posts
    41

    Default Re: Email AfterUpdateRecords Problem

    Thanks Eric...this is very much appreciated. I will play around with using Dialogs.

    Rob

  5. #5
    Member
    Real Name
    Robert Neil
    Join Date
    Nov 2008
    Posts
    41

    Default Re: Email AfterUpdateRecords Problem

    Here is what I ended up with...It works GREAT...Thanks Eric!

    t = table.open("[pathalias.abd_path]\t_safetyrequest_safetyr")
    t.enter_begin()
    t.Dept_idf=alltrim(CurrentForm.Controls.Dept_idf.value)
    t.Safetyr_typef=alltrim(CurrentForm.Controls.Safetyr_Type.value)
    t.Safetyr_categoryf=alltrim(CurrentForm.Controls.Safetyr_Category.value)
    t.Safetyr_locationf=alltrim(CurrentForm.Controls.Safetyr_Location.value)
    t.Safetyr_commentf=alltrim(CurrentForm.Controls.Safetyr_Comment.value)
    t.Safetyr_contactf=alltrim(CurrentForm.Controls.Safetyr_Contact.value)
    t.Safetyr_phonef=alltrim(CurrentForm.Controls.Safetyr_Phone.value)
    t.Safetyr_emailf=alltrim(CurrentForm.Controls.Safetyr_Email.value)
    t.enter_end()
    t.close()

    dim e_to as c
    dim e_cc as c
    dim e_body as c
    dim e_subject as c

    e_to="myemaileddress"
    e_cc=CurrentForm.Controls.Safetyr_Email.value
    e_subject="New "+CurrentForm.Controls.Safetyr_Type.value+" Issue Reported"
    e_body="Thank you for reporting this issue "+CurrentForm.Controls.Safetyr_Contact.value+""+crlf()
    e_body=e_body+"Here is a copy of the information you entered."+crlf(2)
    e_body=e_body+"Department Number: "+CurrentForm.Controls.Dept_idf.value+crlf()
    e_body=e_body+"Hazard Type: "+CurrentForm.Controls.Safetyr_Type.value+crlf()
    e_body=e_body+"Hazard Description: "+CurrentForm.Controls.Safetyr_Category.value+crlf()
    e_body=e_body+"Specific Location: "+CurrentForm.Controls.Safetyr_Location.value+crlf()
    e_body=e_body+"Comments: "+CurrentForm.Controls.Safetyr_Comment.value+crlf()
    e_body=e_body+"Your Name: "+CurrentForm.Controls.Safetyr_Contact.value+crlf()
    e_body=e_body+"Your Phone Number: "+CurrentForm.Controls.Safetyr_Phone.value+crlf()
    e_body=e_body+"Your Email Address: "+CurrentForm.Controls.Safetyr_Email.value+crlf()
    email_send(e_to,e_subject,e_body,"",e_cc,"",.F.,"","","Default")

    CurrentForm.RedirectTarget = "dashboard.htm"

    *****************************

    This is the resulting email:

    Thank you for reporting this issue John Doe.
    Here is a copy of the information you entered.

    Department Number: 000002
    Hazard Type: Fire and Life Safety
    Hazard Description: Storage within 18" of sprinkler head
    Specific Location: Storage Room
    Comments: There are boxes stored on top shelf
    Your Name: John Doe
    Your Phone Number: 9255551212
    Your Email Address: email address entered by user



    One more question. I would like to assign a value stored in another table to the e_to parameter. Is there a way for me to call up another table and retrieve a value from a specific field?

  6. #6
    Member EricN's Avatar
    Real Name
    Eric
    Join Date
    May 2007
    Location
    Minnesota
    Posts
    553

    Default Re: Email AfterUpdateRecords Problem

    So you want to pull an email address from another table to this outgoing email?

    To "pull" a value from another location, you may want to try something like this: alltrim(lookupc("F",alltrim(session.__protected__userid),"alltrim(Email)","[pathalias.adb_path]\users","userid"))

    Go into the help files and search for "lookup" Here you will see some examples.
    Eric

    Alpha Five Websites
    longlivepuppies.com
    socialservicenetwork.com
    -------------------------------------------------
    socialservicenetwork.org

Similar Threads

  1. AfterUpdateRecords
    By Phil Rolf in forum Application Server Version 8
    Replies: 5
    Last Post: 05-10-2008, 12:08 PM
  2. Adding Javascript within the AfterUpdateRecords Grid Event
    By den1s in forum Application Server Version 8
    Replies: 4
    Last Post: 02-29-2008, 03:18 AM
  3. Email problem
    By Bill Warner in forum Alpha Five Version 7
    Replies: 2
    Last Post: 08-01-2007, 03:59 PM
  4. AfterUpdateRecords - Insert Data
    By Rich Hartnett in forum Web Application Server v7
    Replies: 3
    Last Post: 10-16-2006, 03:11 PM
  5. Replies: 2
    Last Post: 01-12-2006, 11:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •