NetTalk Central

Author Topic: Send an email on change of record  (Read 3625 times)

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Send an email on change of record
« on: June 18, 2014, 04:50:09 AM »
On one of my projects I send an email to the client of the fields values if a new record is added to a specific table.
This is simple since I do it in the postInsert embed point.
What I need to do is to send an email with both the old and new fields if a record is changed.
I can do this in the PostUpdate embed point but what is the best way to:
Firstly know that a change was made since it's possible that the user just came into the form and then saved even though nothing was changed.
Secondly what is the best way to store the incoming values so that I can send an email which says something like: address line was change from (incoming_field) to (current_value)?
 
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Send an email on change of record
« Reply #1 on: June 18, 2014, 11:38:37 PM »
so I think your problem breaks down into 2 parts;

a) you want to "store" the record, before the save, so you have something to compare to and
b) you need to do the comparison and then build your email from that.

So let's do the easy bits first. You don't actually have to create a copy - one exists already. If, for example your file field is
Inv:Value
then you can access

p_web.GetSessionValue('_old_Inv:Value')
p_web.GetValue('_old_Inv:Value')

to find the original value before the change.

In terms of constructing the email - there's no method to make that easy for you - you just need to compare all the fields which may have changed, or which you want to report have changed.

eg, in Post-Update

if p_web.GetValue('_old_Inv:Value') <> inv:Value
  ! add to email
end


cheers
Bruce


« Last Edit: September 02, 2014, 12:54:06 AM by Bruce »

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Send an email on change of record
« Reply #2 on: June 19, 2014, 12:18:30 AM »
Thanks Bruce. Exactly what I need.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Send an email on change of record
« Reply #3 on: August 26, 2014, 02:27:59 AM »
Hi Bruce
I put the following trace line in the post update (btw. this is definitely an update, not an insert, the record does exist)

p_web._trace('_old_CLA:ValueInclusive ' & p_web.GetSessionValue('_old_CLA:ValueInclusive') & ' CLA:ValueInclusive ' & CLA:ValueInclusive)

debug view returns this:
[\\TERRYD-PC]
00000003   589.57385254   [16176] [st] [netTalk][thread=3] _old_CLA:ValueInclusive  CLA:ValueInclusive 62.55

There is no value associated with _old_CLA:ValueInclusive
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Send an email on change of record
« Reply #4 on: September 02, 2014, 12:53:04 AM »
my mistake Terry, the old value is in the Value queue, not the session queue.

ie
p_web.GetValue('_old_Whatever')
not
p_web.GetSessionValue('_old_Whatever')

Cheers
Bruce

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Send an email on change of record
« Reply #5 on: September 02, 2014, 01:06:49 AM »
Thanks Bruce
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186