IF statements for strings containing unpaired parentheses
Posted: Tue Sep 12, 2023 4:58 pm
I ran into this issue and couldn't find a solution here, so I thought posting both the problem and solution might be helpful to others.
I was having an issue where an unpaired opening or closing parenthesis was causing the Order.ExistingLiens.Recording.AdditionalInfo field to not complete an IF statement and not render IF used in a IF statement. My guess is that when Select parses the IF statement, it expands the string and treats the next parenthesis it encounters as part of the IF statement rather than ignoring any special characters in the string.
An example of a value in the AdditionalInfo field that will cause this issue is below:
The workaround for this error is to reverse the logic by checking for the values I didn't want and moving the AdditionalInfo to an ELSE statement, as below.
Not that there is no issue if the field is not checked in an IF statement.
I'm sure that there are other special characters or combinations of special characters that will also raise create unexpected output that this may or may not resolve, e.g. "{{" break the IF statement and display document code.
The below in the AdditionalInfo field:
Renders on a document as as:
I was having an issue where an unpaired opening or closing parenthesis was causing the Order.ExistingLiens.Recording.AdditionalInfo field to not complete an IF statement and not render IF used in a IF statement. My guess is that when Select parses the IF statement, it expands the string and treats the next parenthesis it encounters as part of the IF statement rather than ignoring any special characters in the string.
Code: Select all
<FOREACH {{Order.ExistingLiens}}>
<IF (Not IsEmpty( {{.RecordingInformation.AdditionalInfo}} ) and {{.RecordingInformation.AdditionalInfo}} <> "")>
Notes:
{{.RecordingInformation.AdditionalInfo}}
</IF>
</FOREACH>
Code: Select all
a) Substitute Mortgage A in the amount of $1,000,000.00 and b) Substitute Mortgage B in the amount of $500,000.00.
Code: Select all
<FOREACH {{Order.ExistingLiens}}>
<IF (IsEmpty( {{.RecordingInformation.AdditionalInfo}} ) or {{.RecordingInformation.AdditionalInfo}} = "")><ELSE>
Notes:
{{.RecordingInformation.AdditionalInfo}}
</IF>
</FOREACH>
Code: Select all
<FOREACH {{Order.ExistingLiens}}>
Additional Info.: {{.RecordingInformation.AdditionalInfo}}
</FOREACH>
The below in the AdditionalInfo field:
Code: Select all
a{{ Substitute Mortgage A in the amount of $1,000,000.00 and b) Substitute Mortgage B in the amount of $500,000.00.
Code: Select all
<IF ( IsEmpty( "a"" = ““)><ELSE>
Notes:
"a{{ Substitute Mortgage A in the amount of $1,000,000.00 and b) Substitute Mortgage B in the amount of $500,000.00."
</IF>
</FOREACH>