11-21-2022 08:34 AM - last edited on 05-02-2023 10:33 AM by JackLacava
Hi,
Can anyone help in writing a confirmation rule where if Account starts with 4 and U3#00 has a value then the rule fails and the Account name is displayed.
I am getting an error in running through the loop for all the account starting with 4, the rule probably stops at first match itself. If anyone could give the rule from scratch would be great!
Thanks!
11-23-2022 11:01 AM
Untested, but this should give you ideas on how to go about things...
Dim cons As String = args.ConfirmationRuleArgs.DataUnitText.ConsName
Dim entity As String = args.ConfirmationRuleArgs.DataUnitText.EntityName
Dim scenario As String = args.ConfirmationRuleArgs.DataUnitText.ScenarioName
Dim time As String = args.ConfirmationRuleArgs.DataUnitText.TimeName
Dim cube As String = args.ConfirmationRuleArgs.DataUnitText.CubeName
' we get the dataunit, remove zero and nodata, and then filter it
Dim dbf As DataBuffer = api.Data.GetDataBufferUsingFormula( _
$"FilterMembers(RemoveZero(Cb#{cube}:S#{scenario}:E#{entity}:C#{cons}:T#{time}), " & _
"A#AllAccounts.Descendants.Where(Name StartsWith A), " & _
"U3#00)" )
' hashset are basically lists that just ignore duplicates
Dim badAccounts As New HashSet(Of String)
For Each dbCell As DataBufferCell In dbf.DataBufferCells.Values
' this check is somewhat redundant, also ignoring negatives...
If dbCell.CellAmount > 0 Then
badAccounts.Add(dbCell.GetAccountName(api))
End If
Next
If badAccounts.Count > 0 Then
args.ConfirmationRuleArgs.Info1 = String.Join(", ", badAccounts)
Return False
End If
Return True