Alex J
Alex J

Reputation: 1567

save the screen change history in lightswitch app

is there any easy way to track what is changed on a lightswitch app screen?

i have a form that shows information about a customer (listdetail). When I save it, i want to write to a history table what was changed.

Upvotes: 2

Views: 556

Answers (1)

Alex J
Alex J

Reputation: 1567

found the answer here.

Just use the following code in the _updating, _inserting events for the controls.

    Private Sub Employees_Updating(entity As Employee)
       Dim change = entity.EmployeeChanges.AddNew()
       change.ChangeType = "Updated" change.Employee = entity
       change.Updated = Now()
       change.ChangedBy = Me.Application.User.FullName

       Dim newvals = "New Values:"    
       Dim oldvals = "Original Values:"    

       For Each prop In entity.Details.Properties.All().
            OfType(Of Microsoft.LightSwitch.Details.IEntityStorageProperty)()

           If prop.Name <> "Id" Then             

                If Not Object.Equals(prop.Value, prop.OriginalValue) Then                 
                    oldvals += String.Format("{0}{1}: {2}", vbCrLf, prop.Name, prop.OriginalValue)
                    newvals += String.Format("{0}{1}: {2}", vbCrLf, prop.Name, prop.Value)
                End If         
           End If    

       Next   

      change.OriginalValues = oldvals
      change.NewValues = newvals

End Sub 

Upvotes: 3

Related Questions