Normal Topic Tracking changes to a file. (Read 890 times)
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Tracking changes to a file.
Jan 5th, 2016 at 8:01pm
Print Post Print Post  
My application has over a hundred elements.  I want to be able to track when someone makes a change to an element in the file.  I need to know which element was changed (from and to), who made the change, and when it was changed.

Is there a way to do this? 

I know i can track the changes to individual elements, but that would be impractical for every element.

Thanks!
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Tracking changes to a file.
Reply #1 - Jan 5th, 2016 at 8:39pm
Print Post Print Post  
Look in to @TriggeringElement(), and possibly combining it with SetThisElement() like this:
SetThisElement(@TriggeringElement())

This can then be used in a subroutine placed in an event that occurs for every element on the form, like "FormName :: On Element Exit".
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Tracking changes to a file.
Reply #2 - Jan 5th, 2016 at 9:32pm
Print Post Print Post  
I created an element called RecordHistory2 and used the following programming for ON FORM CHANGE for the new element:

RecordHistory2=@date +" " + @triggeringelement()+ " BY: " + @userID

This works in that it tells me who made the change, when the change was made and what element was changed, but it doesn't tell me what was in the element before the change. 

Is there any way to record the element info before the change?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Tracking changes to a file.
Reply #3 - Jan 6th, 2016 at 3:42am
Print Post Print Post  
In some cases you can grab the "undo value" of a recently changed element:

In Form or Element change event, where "Company" is the element:
Code
Select All
#include "sbasic_include.sbas"

var str as string

str = @Attribute(Company, ATTR_ID_UNDO_VALUE)
writeln(str)
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Tracking changes to a file.
Reply #4 - Jan 6th, 2016 at 1:34pm
Print Post Print Post  
I tried using your programming but I modified it slightly.  Since I don't know which element will be changed, I added a second variable and used @TriggeringElement to set the variable to the element name:

#include "sbasic_include.sbas"

var str as string
var str2 as string

str2=@triggeringelement()
str = @Attribute(str2, ATTR_ID_UNDO_VALUE)

However, though I get the element name assigned to Str2 correctly, the @Attribute statement doesn't work.

If I put the element name directly into the @Attribute statement (see below), it works as expected.  Does @Attribute work with variables for element names?  Any suggestions?

(str = @Attribute(gmold#,ATTR_ID_UNDO_VALUE)

  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Tracking changes to a file.
Reply #5 - Jan 6th, 2016 at 2:31pm
Print Post Print Post  
NHUser wrote on Jan 6th, 2016 at 1:34pm:
If I put the element name directly into the @Attribute statement (see below), it works as expected.  Does @Attribute work with variables for element names?  Any suggestions?



It does work with variables, but not with string variables. You need an element reference. You can convert a string to an element reference using @field.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
NHUser
Full Member
***
Offline



Posts: 320
Location: Amherst, NH
Joined: Aug 2nd, 2010
Re: Tracking changes to a file.
Reply #6 - Jan 6th, 2016 at 4:34pm
Print Post Print Post  
Thanks for your help.  I used the following programming incorporating @field and it works great!



#include "sbasic_include.sbas"

var str as string
var str2 as string

str2=@triggeringelement()
str = @Attribute(@field(str2), ATTR_ID_UNDO_VALUE)

RecordHistory2=RecordHistory2+@Newline()+@date +" " + @triggeringelement()+ " BY: " + @userID + " WAS: "+ Str

  
Back to top
 
IP Logged