Forum Discussion
BRujawitz
7 days agoNew Contributor
This is the code that worked for me: I used IC and Entity and assumed that they should not match. I also added an example if two pre transformed entities map to one entity in OneStream. This works for Delimited files.
Dim ICcol As String = args.Value.Trim()
Dim Entcol As String = api.Parser.DelimitedParsedValues(1).Trim()
'Column 2 holds the Entity information - you must subtract 1 from column value for the Complex Expression
' Convert both to uppercase for case-insensitive comparison
Dim ICcolUpper As String = ICcol.ToUpper()
Dim EntcolUpper As String = Entcol.ToUpper()
If (ICcolUpper = EntcolUpper) _
Or ((ICcolUpper = "XXXXX" And EntcolUpper = "YYYYY") _
Or (EntcolUpper = "XXXXX" And ICcolUpper = "YYYYY")) Then
Return "None"
Else
Return ICcol
End If
RobbSalzmann
6 days agoValued Contributor II
BRujawitz​ your code is a bit brittle. Consider using built in String.Equals() and employing StringComparison instead of creating new strings through converting strings to upper case, also, remember to use sort circuit operators (AndAslo, OrElse) wherever possible in logical evaluations:
Dim ICcol As String = args.Value.Trim()
Dim Entcol As String = api.Parser.DelimitedParsedValues(1).Trim()
If String.Equals(ICcol, Entcol, StringComparison.OrdinalIgnoreCase) _
Or (String.Equals(ICcol, "XXXXX", StringComparison.OrdinalIgnoreCase) AndAlso String.Equals(Entcol, "YYYYY", StringComparison.OrdinalIgnoreCase)) _
Or (String.Equals(Entcol, "XXXXX", StringComparison.OrdinalIgnoreCase) AndAlso String.Equals(ICcol, "YYYYY", StringComparison.OrdinalIgnoreCase)) Then
Return "None"
Else
Return ICcol
End If
Finally, I would refactor the above for readability (self documenting code) and proper null checking to help avoid unforeseen runtime exceptions as follows:
Dim rawIC As String = args?.Value
Dim rawEnt As String = api?.Parser?.DelimitedParsedValues(1)
' Safely trim and default to empty string if null
Dim ICcol As String = If(rawIC, "").Trim()
Dim Entcol As String = If(rawEnt, "").Trim()
Dim isSameEntity As Boolean = String.Equals(ICcol, Entcol, StringComparison.OrdinalIgnoreCase)
Dim isSwapPair As Boolean = _
(String.Equals(ICcol, "XXXXX", StringComparison.OrdinalIgnoreCase) AndAlso String.Equals(Entcol, "YYYYY", StringComparison.OrdinalIgnoreCase)) _
Or (String.Equals(ICcol, "YYYYY", StringComparison.OrdinalIgnoreCase) AndAlso String.Equals(Entcol, "XXXXX", StringComparison.OrdinalIgnoreCase))
If isSameEntity OrElse isSwapPair Then
Return "None"
Else
Return ICcol
End If
Related Content
- 4 years ago
- 10 months ago