Loop through Account for Confirmation Rules

xtensibilitybro
New Contributor III

Hello, 

I am looking to  write a confirmation rule which pulls a value for a flow member across each account. An example would be we have a calculated opening balance and a loaded opening balance. There is a flow members which calculates the variance between the loaded and the calculated beginning balance. 

If the absolute value within the validation flow member <> 0 I want the rule to return which accounts are causing the outage within the info1. 

I'm looking forward to seeing if if anyone else has come across something like this.

Cheers!

 

1 REPLY 1

JackLacava
Community Manager
Community Manager

This sounds like "do my homework" eh 😏 I'd suggest starting with this old ppt... But here's some untested code to give you an idea for a possible technique.

 

' F#YourBalanceFlow is probably too generic, you should add as many other dimensions as you can
Dim BadAccounts as new List(Of Integer)
Dim dbuf As DataBuffer = api.Data.GetDataBufferUsingFormula( _
		"FilterMembers(F#YourBalanceFlow, A#Account1, A#Account2, A#Account3)")  ' etc etc, or use expansions
For Each myCell As DataCell In dbuf.DataBufferCells.Values
	If Not BadAccounts.Contains(myCell.DataCellPk.AccountId) Then
		If myCell.CellAmount <> 0 Then
			BadAccounts.Add(myCell.DataCellPk.AccountId)
		End If
	End If
Next

If BadAccounts.Count > 0 Then
	Dim message As String = $"The following accounts failed validation: {VbCrLf}"
	For Each accountId As Integer In BadAccounts
		' turn that ID into a readable account name
		message &= api.Members.GetMemberName(dimtype.Account.Id, accountId) & $" {VbCrLf}"
	Next
	args.ConfirmationRuleArgs.Info1 = message
	Return False
End If
args.ConfirmationRuleArgs.Info1 = "All good, surf up dude"
Return True