Get field value before updating it

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ProxyKing
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6
Joined: Tue Sep 04, 2007 5:27 pm

Get field value before updating it

Post by ProxyKing » Thu Oct 28, 2010 1:33 am

Hey guys,

I have a silly problem... I'm trying to get the value of the field BEFORE I change it. I thought that enterInField might work but then read about it. Nope. Barking up the wrong tree. The user won't always select the field with a mouse but might stumble into the field after changing another field and hitting the ENTER key.

What I am trying to do is to create a changeLog so when someone changes the field's value (by any means) it will store the before and after value in a DB.

Any thoughts...?

Thanks
Paul

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Get field value before updating it

Post by Klaus » Thu Oct 28, 2010 9:32 am

Hi Paul,

maybe "openfield" is what you are looking for?


Best

Klaus

ProxyKing
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6
Joined: Tue Sep 04, 2007 5:27 pm

Re: Get field value before updating it

Post by ProxyKing » Thu Oct 28, 2010 7:22 pm

Hey Klaus,

I do use that as well as focusIn. I've updated to 4.5 (dp3) and now for some odd reason it works! <smacks head>
It could have been a minor glitch in dp1 that was fixed in dp3..? I was going nuts. I have it as a behavior as I have quite a few fields that access the same code.

Code: Select all

on openField
   set the oldValue of this stack to me
   answer me  --see if it does grab the value
end openField

Code: Select all

on focusIn
   set the oldValue of this stack to me
end focusIn
Thanks!
Hope to see you at RevCon 2011
Paul

ProxyKing
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6
Joined: Tue Sep 04, 2007 5:27 pm

Re: Get field value before updating it

Post by ProxyKing » Thu Oct 28, 2010 8:19 pm

Nope. I AM going nuts. When I try it out on a single field it works fine. It will store the old value and the new value. When I hit ENTER and go to the next field, I only get the new value in the table.

I'm doing something wrong... I know this. But what and where...?

Code: Select all

on closeField
   createAuditTrail
end closeField

Code: Select all

on openField
  --this works
   put me into fld "oldValue"
end openField

Code: Select all

on focusIn
   openField
end focusIn

Code: Select all

on createAuditTrail
   put empty into changeData
   put "kasinstrux" into changeData["theTable"]
   put word 2 of (the effective name of me) into changeData["theField"]
   put fld "oldValue" into changeData["oldValue"]
   put fld "Broker" into changeData["PrimaryValue"]
   put "BankSym" into changeData["PrimaryKey"]
   put "Curr" into changeData["SecondaryKey"]
   put fld "Curr" into changeData["SecondaryValue"]   
   put me into changeData["NewValue"]
   updateChangeLog changeData  --basic insert query used
   put word 2 of (the effective name of me) into theField
   replace quote with empty in theField
   put quoteIt(titleCase(me)) into theValue
   --update the DB with the change made
   updateKASInstrux theField,theValue,fld "Curr",fld "Broker"
end createAuditTrail
Does anyone see something glaringly simple that I keep tripping over..?

Post Reply