This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can the History Database be accessed from the API?

We have a tool that uses the API to read the tables used for the time trace data. Adding the History Database... the data as expected gets moved to the History DB. Is there a way to access the history database from the API/App Server? 

-Josh

Parents
  • When you say API/App Server, do you refer to the REST API or if it is possible to access the historical data using the object layer?

  • REST API. Do we have to install a second instance pointed to the History DB? Is that possible?

  • I have never seen that someone has installed an application server against a History DB installation. So it would be a first one for you to try. Theoretically, you should be able to access the History DB tables then but again, I have never tried or seen that before.

    For the object layer, there are methods and functions available to access and retrieve historical objects. But if you want to access the data using the REST API you would need to wrap that in calls to scripts that return a single value, potentially a JSON.

    What is your use-case for using the REST API to access the historical data from the History DB?

  • We present the Time Trace data on a customer focused web application.

  • What methods are you referring to? What would be the best way to retrieve all the time trace data for a single person record? Currently I read 4 or 5 different tables and piece a picture together.

  • Then my last post is everything I've got. Create custom scripts that fetch the data according to your use-case and return a JSON formatted result. This would be my solution.

  • At first glance seems a second API/App server instance works. Thanks.

  • Okay. A sample for using the object layer in a script to access the changes from TimeTrace for an object would be the following function:

    Public Function SDK_GetHistory(ByVal objectKey As String, Optional BackTo As DateTime = Nothing) As String
    
        ' Resolve history source
        Dim source = Session.Resolve(Of History.IHistorySource)()
    
        ' Fetch an enumerator over all change infos in descending date order (based on objectkey) 
        Dim changes = source.GetChangesAsync(New DbObjectKey(objectKey), BackTo, History.HistoryMode.WithNewValues Or History.HistoryMode.WithFkDisplays).Result
    
        ' Initialize StringBuilder
        Dim strChanges As StringBuilder = New StringBuilder(512)
        strChanges.AppendLine("Changed at;Changed by;Operation;ColumnName;OldValue;NewValue;OldValueDisplay;NewValueDisplay")
    
        ' Iterate over each change
        For Each change In changes
            ' Iterate over every changed column
            For Each column In change.Changes
                ' Do something with the data.
                strChanges.AppendLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7}",
                                                   change.ChangeTime.ToString,
                                                   change.User,
                                                   change.ChangeType.ToString,
                                                   column.Columnname,
                                                   column.OldValue,
                                                   column.OldDisplay,
                                                   column.NewValue,
                                                   column.NewDisplay))
            Next
        Next
        Return strChanges.ToString
    
    End Function

Reply
  • Okay. A sample for using the object layer in a script to access the changes from TimeTrace for an object would be the following function:

    Public Function SDK_GetHistory(ByVal objectKey As String, Optional BackTo As DateTime = Nothing) As String
    
        ' Resolve history source
        Dim source = Session.Resolve(Of History.IHistorySource)()
    
        ' Fetch an enumerator over all change infos in descending date order (based on objectkey) 
        Dim changes = source.GetChangesAsync(New DbObjectKey(objectKey), BackTo, History.HistoryMode.WithNewValues Or History.HistoryMode.WithFkDisplays).Result
    
        ' Initialize StringBuilder
        Dim strChanges As StringBuilder = New StringBuilder(512)
        strChanges.AppendLine("Changed at;Changed by;Operation;ColumnName;OldValue;NewValue;OldValueDisplay;NewValueDisplay")
    
        ' Iterate over each change
        For Each change In changes
            ' Iterate over every changed column
            For Each column In change.Changes
                ' Do something with the data.
                strChanges.AppendLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7}",
                                                   change.ChangeTime.ToString,
                                                   change.User,
                                                   change.ChangeType.ToString,
                                                   column.Columnname,
                                                   column.OldValue,
                                                   column.OldDisplay,
                                                   column.NewValue,
                                                   column.NewDisplay))
            Next
        Next
        Return strChanges.ToString
    
    End Function

Children