Original Field Value


Author
Message
Tim Dol
Tim Dol
StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
I need to compare the current value of a field with the original value. Where can I find the original value within the BO. 

Thanks

Tim

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If the field is a normal field, then I believe the underlying DataTable tracks this. Check out the properties for the CurrentRow (which just wraps the current DataRow of the underlying DataTable).



If it's a custom field, then you'd have to manage the original value yourself.
Tim Dol
Tim Dol
StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
I checked the current row and the value seems to reflect the changes I made to the field.

I want to be able to compare the current value to the original value in the AfterSave event, if the original data is available. I need to perform some automated functions if certain values change so I need access to the original data. I'm sure Trent told me a while back where to find this information but I can't find the post.

Tim

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Oh, I believe the original value is "gone" in the AfterSave event. I.e. once the BO saves the data, the datatable updates its original value to the latest value so it knows when it is dirty again. You might need to figure this out in the BeforeSave event. At least you could see if you can get access to the original value in the BeforeSave event.
Tim Dol
Tim Dol
StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
Actually I have been looking at this on a row by row basis, when I really should be looking at this from the currentdatatable perspective, so I guess I will need to loop through the BO and check values for any rows that have changed.

Any suggestions on how/where I should be adding the compare logic, (BeforeSave, AfterSave?)  to implement this type of logic and how I get access to original values.

Basically I need to execute routines when specific fields have been changed. Example: Automatically create a note on the customer's account when the user changes the credit limit.

Any help is appreciated.

Thanks

Tim

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
To find the original values versus the new values (current values) use something like this:



'-- Get the current value of the current row

' Note the use of the FieldNames enum (created for each BO)

Dim currValue As String = MyBo.CurrentRow.Item(MyBoFieldNames.MyField,DataRowVersion.Current)

'-- Get the original value of the current row

Dim orgValue As String = MyBo.CurrentRow.Item(MyBoFieldNames.MyField,DataRowVersion.Original)



'-- To loop through all the rows, checking if the row is dirty, then getting the original values.

For Each row As DataRow In MyBo.CurrentDataTable.Rows

'-- Get org Value if its dirty

If row.RowState <> DataRowState.Unchanged Then

'-- Get original values

' Note that the field name is just referenced by its name as a string here.

Dim orgValue2 As Integer = row.Item("intField",DataRowVersion.Original)

End If

Next





You will need to do this BEFORE the record is saved. When it is saved, the original values are reset to the current values. I'd also make sure to check AFTER the rules are checked, in case there are broken rules. Likely, I'd do the checking after the rules are checked, save away the results, then take action after the save actually works. I might also do it within a transaction, just in case...



Good luck!
Tim Dol
Tim Dol
StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)StrataFrame User (408 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
Thanks a lot Greg, this will definetly get me started in the right direction. Much appreciated.Smile

Tim

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'm glad I've been a help! Good luck!
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Greg is perfectly correct in the use of the DataRowVersion.Original when you call the CurrentRow("FieldName", version) property, but in the AfterSave event, the changes have already been comitted to the DataTable.

Even if you change the AcceptRowChangeMode to AfterTableSave, the whole table will have been accepted before the AfterSave event has been copied.  The only way that I can think to test this would be to copy the CurrentDataTable before the save.  If you use CurrentDataTable.Copy() and store the result in a variable, it will take an exact snapshot of the data in the DataTable and you'll be able to use that to get your original values.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search