I’m looking to create a form specific (even full loan file) change log and have this codebase setup which works great except for the fact that I can’t get it to stop capturing the logs of the field that I’m sending the log data to. So anytime a change is made, it sends it to CX_MONITOR_LOG which is great except then it captures the change to CX_MONITOR_LOG and basically is stuck in a loop.
I tried adding error logs that don’t capture anything, throwing this in chatgpt, rewriting it a few ways and have had no luck.
Imports EllieMae.Encompass.Forms
Imports EllieMae.Encompass.BusinessObjects.Loans
Imports EllieMae.Encompass.Automation
Public Class DemoForm
Inherits Form
Private Shared isLogging As Boolean = False
Private Const ERROR_LOG_FIELD_ID As String = "CX_ERROR_LOG" ' Replace with your actual custom error log field ID
Private Shared eventHandlerAttached As Boolean = False
' Constructor to attach the Load event handler
Public Sub New()
AddHandler Me.Load, AddressOf FormLoadHandler
End Sub
' Method to handle the form load event
Public Sub FormLoadHandler(sender As Object, e As EventArgs)
InitializeLogger()
End Sub
' Method to initialize the field change logger
Public Sub InitializeLogger()
' Ensure the FieldChangeHandler is only attached once
If Not eventHandlerAttached Then
AddHandler EllieMae.Encompass.Automation.EncompassApplication.CurrentLoan.FieldChange, AddressOf FieldChangeHandler
eventHandlerAttached = True
End If
End Sub
' Event handler for field changes
Private Sub FieldChangeHandler(sender As Object, e As FieldChangeEventArgs)
' Avoid logging changes to CX_MONITOR_LOG or ERROR_LOG_FIELD_ID to prevent recursion
If e.FieldID = "CX_MONITOR_LOG" OrElse e.FieldID = ERROR_LOG_FIELD_ID Then
Return
End If
' Prevent recursive logging
If isLogging Then
Return
End If
isLogging = True
Try
' Create a log entry
Dim logEntry As String = String.Format("{0}: Field {1} changed to: {2}", DateTime.Now, e.FieldID, e.NewValue)
' Log the change to the custom error log field
Dim errorLogField As Field = EllieMae.Encompass.Automation.EncompassApplication.CurrentLoan.Fields(ERROR_LOG_FIELD_ID)
If errorLogField IsNot Nothing Then
errorLogField.Value &= logEntry & vbCrLf
End If
Catch ex As Exception
' Log the error to the custom error log field
Dim errorLogField As Field = EllieMae.Encompass.Automation.EncompassApplication.CurrentLoan.Fields(ERROR_LOG_FIELD_ID)
If errorLogField IsNot Nothing Then
errorLogField.Value &= "Error during logging: " & ex.Message & vbCrLf
End If
Finally
' Ensure the flag is reset
isLogging = False
End Try
End Sub
End Class
Griffin Rossi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.