EncompDEV
LoanDebugger2

Admin Form - Field Values

Click here to download this form
Simple form that allows you to copy-paste field trigger code or condition and see the values of all fiels used in the trigger. Useful to quickly check if a rule would trigger on a change. Also allows to check/set fields manually for more testing.
Example #1 - values for fields from Condition:
Example #2 - values for Borrower Pairs:

Code on this form uses Regular Expressions to extract values between square brackets, dictionary to collect unique field IDs and a list to sort fields alphabetically.

Dim sInput As String = txtInput.Text

' store unique field IDs that we find within code
Dim dictFields As New System.Collections.Generic.Dictionary(Of String, String)

' split field IDs with Regex and put unique fields into dictFields
Dim sFieldID As String
Dim mc As System.Text.RegularExpressions.MatchCollection
mc = System.Text.RegularExpressions.Regex.Matches(sInput, "\[(.*?)\]")
Dim m As System.Text.RegularExpressions.Match
For Each m In mc
    Try
        sFieldID = m.Groups(1).Value.ToUpper().Trim()
        ' if field has a known type prefix - remove it
        ' '#' - Decimal          0 when empty
        ' '@' - DateTime         DateTime.MinValue when empty
        ' '+' - Formatted Str    "//" on empty dates
        ' '-' - Unformatted Str  "" on empty dates
        If sFieldID.StartsWith("#") Or _
           sFieldID.StartsWith("@") Or _
           sFieldID.StartsWith("+") Or _
           sFieldID.StartsWith("-") Then
            sFieldID = sFieldID.Substring(1)
        End If
        ' store field in the dictionary for lookup
        If Not dictFields.ContainsKey(sFieldID) Then
            dictFields.Add(sFieldID, sFieldID)
        End If
    Catch
        ' it's not a big deal if some fields don't parse
    End Try
Next

' convert to list and sort alphabetically
Dim lstFields As System.Collections.Generic.List(Of String)
lstFields = New System.Collections.Generic.List(Of String)(dictFields.Keys)
lstFields.Sort()

' show all field values
Dim sAllFields As String = ""
For Each sFieldID In lstFields
    Dim sValue As String = ""
    Try
        ' is there a suffix for borrower pair?
        Dim iBorrowerPair As Integer = -1 ' 0-based index
        Dim i1 As Integer = sFieldID.LastIndexOf("#")
        If i1 > 0 Then
            ' # suffix is 1-based, we need 0-based
            iBorrowerPair = CInt(sFieldID.Substring(i1 + 1)) - 1
        End If
        If iBorrowerPair < 0 Then
            ' normal field without borrower pair
            sValue = Loan.Fields(sFieldID).FormattedValue
        ElseIf iBorrowerPair >= Loan.BorrowerPairs.Count Then
            ' borrower pair index out of range - empty value
            sValue = "- empty, borrower pair does not exist"
        Else
            ' borrower pair value
            Dim bp As EllieMae.Encompass.BusinessObjects.Loans.BorrowerPair
            bp = Loan.BorrowerPairs(iBorrowerPair)
            sValue = Loan.Fields(sFieldID).GetValueForBorrowerPair(bp)
        End If
    Catch ex As Exception
        sValue = "ERROR: " + ex.Message
        sValue = sValue.Replace(vbCr, " ").Replace(vbLf, " ").Replace(vbTab, " ")
        sValue = sValue.Replace("Parameter name: fieldId", "")
        sValue = sValue.Replace("  ", " ")
        sValue = sValue.Replace("  ", " ")
        sValue = sValue.Trim()
    End Try
    sAllFields = sAllFields + sFieldID + vbTab + sValue + vbCrLf
Next

txtOutput.Text = sAllFields