NetTalk Central

Author Topic: Updating fields during record change or insert  (Read 3315 times)

DonnEdwards

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Insights and Rants
    • Email
Updating fields during record change or insert
« on: April 17, 2021, 01:20:10 PM »
I have a field in each table in my NT Server app called "UpBy". It's a string field of 200 characters. I want to be able to put some text in it that indicates who inserted or updated it, assuming they made a change and didn't just view it. Something like

DonnEdwards 2021-04-17 23h08 Add 155.93.152.18

Firstly,  where do I initialise a session variable "UserName" to read "Not Logged In"? Once the user logs in I will change it to the actual user name.

Secondly, where do I put the code to generate the string, assuming I want this string to be the session variable "UserName" followed by the date and time, followed by the word "Add" or "Change", followed by the user's IP address?

Thirdly, how do I detect whether the record is being inserted or updated? Also, how do I avoid changing the field if the record hasn't been modified?

All suggestions, ideas and tips will be most welcome. I'm still busy with RTFM, so please forgive me if this is discussed in the documentation. Just point me to an example or section of the notes.
If you're happy with your security, then so are the bad guys

rainerwallenius

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
    • Email
Re: Updating fields during record change or insert
« Reply #1 on: April 18, 2021, 10:35:40 PM »
Hi Donn

You can check p_web.formsettings.action = Net:ChangeRecord (or Net:ChangeRecord, Net:CopyRecord etc)

About detecting changes in data:
In procedure data I have added a line:

OrigRecord   LIKE(XXX:Record),Pre(XXXO)

in preupdate I have:
p_web.ssv('OrigRecord',XXX:Record)

in validateupdate-embed:

OrigRecord = p_web.gsv('OrigRecord')
then check id OrigRecord <> XXX:Record then add the changestring to your field

in ValidateInsert:
Just put your change-string in appropriate field

It's good enough for my needs.

:: rainer

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Updating fields during record change or insert
« Reply #2 on: April 19, 2021, 02:15:09 AM »
>> Firstly,  where do I initialise a session variable "UserName" to read "Not Logged In"? Once the user logs in I will change it to the actual user name.

WebHandler procedure, NewSession method, after Parent call.

>> Secondly, where do I put the code to generate the string,

Form, Priming tab. - probably an AssignOnSave in your case...

<< Thirdly, how do I detect whether the record is being inserted or updated?

Priming tab has options for either / both.

>> Also, how do I avoid changing the field if the record hasn't been modified?

you'd have to make a copy of the record in the session queue and compare it to that.

Cheers
Bruce