The OneStream Community is temporarily frozen until June 29th due to the ongoing maintenance. Please read the blog post here to learn more.
Forum Discussion
Richard_Mayo
2 years agoNew Contributor III
Pass in parameters to a public function
Morning All,
I'm working on a new solution to avoid having many, many separate confirmation rules with their own code which is almost identical in each case, and instead move to using a public func...
- 2 years ago
Hi,
just add the parameter in whichever form you need to the function and pass it on like that. E.g. by adding myParameterDictionary as an object.
Public Function SecondFunction(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As FinanceRulesApi, ByVal args As FinanceRulesArgs, ByVal myParameterDictionary As Object) As ObjectYou then call this function like that:
SharedRule.SecondFunction(si,globals,api,args,myParameterDictionary)If you do not get it to work right away, maybe try passing on a "ByVal mySingleStringParameter as String" first and write that into the error log.
- 2 years ago
Richard_Mayo Business Rules are Namespaces. Namespaces contain Classes. Classes contain Methods (functions and subs). all of this lends itself well for your Object Oriented Programming (OOP) goal here of Code Reuse.
Code reuse is a central design philosophy of proper OOP coding.
Here is a sample way to use this design format to create parameterized, reusable Confirmation Rule logic. Doing it this way can significantly reduce development time and maintenance effort by reducing code complexity and repetition.
Here is a very simple use of a Finance rule to containerize a set of parameterized Confirmation Rule functions:Namespace OneStream.BusinessRule.Finance.ConfirmationRules Public Class CubeDataValidations Public Function ValidateCubeDataMonthly(si As SessionInfo, api As FinanceRulesApi, args As FinanceRulesArgs, accountName As String) As (result As String, message As String) Try If accountName.Equals("SomeAccount", StringComparison.CurrentCultureIgnoreCase) Then Return ("Pass", "Validation succeeded") Else Return ("Warning", "Account name does not match 'SomeAccount'") End If Catch ex As Exception ErrorHandler.LogWrite(si, New XFException(si, ex)) Return ("Fail", "An error occurred during validation") End Try End Function End Class End NamespaceThis code is then consumed repetitively in Confirmation Rules:
- 2 years ago
Hi Richard_Mayo you got it!.
The return type of ValidateCubeDataMonthly is called a "Tuple". A tuple is a nice way to return a few things in one neat package when referencing a custom object at both ends of the code isn't feasible.
In your new case you've created a tuple consisting of a string result, a string message, and a boolean value for passFail.
It looks like this:(result As String, message As String, passfail as boolean)and it is assigned/returned like this:
Dim result as String = "this is the result" Dim message as String = "This is the message" Dim isPass as Boolean = False 'this validation failed Return (result, message, isPass)Make sure you update the method signature of your function to use the new tuple:
Public Function ValidateCubeDataMonthly(si As SessionInfo, api As FinanceRulesApi, args As FinanceRulesArgs, accountName As String) As (result As String, message As String, passfail as Boolean)Then in your calling code, in the confirmation rule, assign and consume the new tuple:
Dim validationResult as (result As String, message As String, passfail As Boolean) validatinResult = cubeData.ValidateCubeDataMonthly(si, api, args, "SomeAccountName")
RobbSalzmann
2 years agoValued Contributor II
Richard_Mayo Business Rules are Namespaces. Namespaces contain Classes. Classes contain Methods (functions and subs). all of this lends itself well for your Object Oriented Programming (OOP) goal here of Code Reuse.
Code reuse is a central design philosophy of proper OOP coding.
Here is a sample way to use this design format to create parameterized, reusable Confirmation Rule logic. Doing it this way can significantly reduce development time and maintenance effort by reducing code complexity and repetition.
Here is a very simple use of a Finance rule to containerize a set of parameterized Confirmation Rule functions:
Namespace OneStream.BusinessRule.Finance.ConfirmationRules
Public Class CubeDataValidations
Public Function ValidateCubeDataMonthly(si As SessionInfo, api As FinanceRulesApi, args As FinanceRulesArgs, accountName As String) As (result As String, message As String)
Try
If accountName.Equals("SomeAccount", StringComparison.CurrentCultureIgnoreCase) Then
Return ("Pass", "Validation succeeded")
Else
Return ("Warning", "Account name does not match 'SomeAccount'")
End If
Catch ex As Exception
ErrorHandler.LogWrite(si, New XFException(si, ex))
Return ("Fail", "An error occurred during validation")
End Try
End Function
End Class
End Namespace
This code is then consumed repetitively in Confirmation Rules:
Richard_Mayo
2 years agoNew Contributor III
Hi Robb,
This is awesome, thanks so much for sharing the code, that is super useful!
And yes I'm looking forward to getting this working to cut down on the maintenance I currently have.
Just one thing - to set the green/red status of the confirmation rule, presumably you could extend your code and have more than 2 things being sent back? eg:
Public Function ValidateCubeDataMonthly(si As SessionInfo, api As FinanceRulesApi, args As FinanceRulesArgs, accountName As String) As (result As String, message As String, passfail as boolean)Then I would use the additional "passfail" that is sent back to set the confirmation rule status.
Not urgent as I'll have a play around with this, just checking I'm on the right lines.
Thanks again,
Richard
- RobbSalzmann2 years agoValued Contributor II
Hi Richard_Mayo you got it!.
The return type of ValidateCubeDataMonthly is called a "Tuple". A tuple is a nice way to return a few things in one neat package when referencing a custom object at both ends of the code isn't feasible.
In your new case you've created a tuple consisting of a string result, a string message, and a boolean value for passFail.
It looks like this:(result As String, message As String, passfail as boolean)and it is assigned/returned like this:
Dim result as String = "this is the result" Dim message as String = "This is the message" Dim isPass as Boolean = False 'this validation failed Return (result, message, isPass)Make sure you update the method signature of your function to use the new tuple:
Public Function ValidateCubeDataMonthly(si As SessionInfo, api As FinanceRulesApi, args As FinanceRulesArgs, accountName As String) As (result As String, message As String, passfail as Boolean)Then in your calling code, in the confirmation rule, assign and consume the new tuple:
Dim validationResult as (result As String, message As String, passfail As Boolean) validatinResult = cubeData.ValidateCubeDataMonthly(si, api, args, "SomeAccountName")
- Richard_Mayo2 years agoNew Contributor III
Brilliant! Thanks for the detailed response, I'm learning a lot! (Now I know what a tuple is so thankyou!)
Really appreciate your time on this.
Regards,
Richard
Related Content
- 3 years ago
- 2 years ago