How to know what fields has changed on the BO when the saved


Author
Message
Jeff Pagley
Jeff Pagley
StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
Hi SF,

My client has asked me to send an email alert when a value has changed in a field for a record.  Is there an event the BO fires that I can handle which tells me what fields has changed and the before and after values of those fields?

Or does anyone have any suggestions on how I can do this?

Thanks,

Jeff

Using C#/Visual Studio 2008
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
If you want to do it via BO you can use the DataRowVersion on the underlying datarows

If NOT BO.CurrentRow.Item(colCount, Data.DataRowVersion.Original) = BO.CurrentRow.Item(colCount, Data.DataRowVersion.Current) Then

or if you want it all on the SQL Server you could do a trigger that looks at the values in the internal INSERTED AND DELETED tables

Keith Chisarik
Jeff Pagley
Jeff Pagley
StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
Hi Keith,

How can I tell what field has changed on the BO?  Is there a way to know what are the before and after values of the field of the BO? And what BO event would I handle to access this info?  Any code examples would be appreciated.

I don't what to audit the information, but I want to send an email when certain fields' values changed in a record.  Therefore, I don't need to setup SQL triggers.

Thanks,

Jeff

Using C#/VS 2008
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
I put a line of code on my reply that should get you pointed in the right direction:

Call the below in a loop for each column in each row you want to check.

If NOT BO.CurrentRow.Item(colCount, Data.DataRowVersion.Original) = BO.CurrentRow.Item(colCount, Data.DataRowVersion.Current) Then

Additional Info:

http://msdn.microsoft.com/en-us/library/system.data.datarowversion.aspx

Keith Chisarik
Jeff Pagley
Jeff Pagley
StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
I will start from there as you suggested.

Thank you for your help.

Jeff
Sam Tenney
Sam Tenney
StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)
Group: StrataFrame Users
Posts: 70, Visits: 3.5K
I am a beginner and I must be missing something simple.

In the BeforeSave method of my BO, I want to compare the current value of a field to the original value.  I am using C# and Visual Studio 2008 and when I try to enter:

If (!BO.CurrentRow.Item(colCount, Data.DataRowVersion.Original) == BO.CurrentRow.Item(colCount, Data.DataRowVersion.Current))

it appears that BO.CurrentRow does not have a method named Item.  What am I doing wrong?

Sam Tenney
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)StrataFrame VIP (1.5K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
if BO is a business object, its currentrow has an item property, in the code snippet above BO is just a placeholder for an actual business object

Quick and dirty code you can use on any SF form with a Primary BO is below. Not efficient if the BO has many rows, but you can always skinny it down if you need to.

For colCount = 0 To Me.PrimaryBusinessObject.CurrentDataTable.Columns.Count - 1

If Not Me.PrimaryBusinessObject.CurrentRow.Item(colCount, Data.DataRowVersion.Original) = Me.PrimaryBusinessObject.CurrentRow.Item(colCount, Data.DataRowVersion.Current) Then

MsgBox("Changed row old value: " & Me.PrimaryBusinessObject.CurrentRow.Item(colCount, Data.DataRowVersion.Original) & vbCrLf & "Changed row new value: " & Me.PrimaryBusinessObject.CurrentRow.Item(colCount, Data.DataRowVersion.Current))

End If

Next

 



Keith Chisarik
Jeff Pagley
Jeff Pagley
StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
I have been testing this code in the BO_BeforeSave event and it seems to work:



// Established a local for the BO's current row

DataRow dataRow = this.CurrentRow;

// Iterate through the columns of the data table

foreach (DataColumn item in this.CurrentDataTable.Columns)

{

// Determine what data row column to retrieve it's value

if (item.ColumnName.Equals("cc_Description") || item.ColumnName.Equals("coco_Description"))

{

// Compare the original version with the current to determine if it changed

if (dataRow[item.ColumnName, DataRowVersion.Original] != dataRow[item.ColumnName, DataRowVersion.Current])

{

Console.WriteLine(String.Format("Table: {0}", this.TableName));

Console.WriteLine(String.Format("Col ({0}) Original = {1} Current = {2}", item.ColumnName, dataRow[item.ColumnName, DataRowVersion.Original].ToString(), dataRow[item.ColumnName, DataRowVersion.Current].ToString()));

}

}

}



I hope this is helpful.

Jeff
Sam Tenney
Sam Tenney
StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)StrataFrame Novice (102 reputation)
Group: StrataFrame Users
Posts: 70, Visits: 3.5K
Thanks Keith and Jeff,

I think I finally figured out that in C#, the CurrentRow does not have a property named Item.  So the C# code I am using is:

if (! BO.CurrentRow[colCount, Data.DataRowVersion.Original] == BO.CurrentRow[colCount, Data.DataRowVersion.Current])

which I think is logically equivalent to Keith's VB code as follows:

If NOT BO.CurrentRow.Item(colCount, Data.DataRowVersion.Original) = BO.CurrentRow.Item(colCount, Data.DataRowVersion.Current)

Notice the C# code does not use an Item property.  If I am off base, please let me  know.

Sam Tenney
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