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
adykes
2 years agoNew Contributor III
Issue With Referencing Global Variables in Connector Business Rules
Hi all,
I am facing an issue regarding my ability to reference global objects between two different business rules, one of which is a finance business rule and the other of which is a connector bu...
- 2 years ago
I haven't used the ExecuteMethodCommand, but it generally looks like it should work. It probably wants the Application Connection Info; BRApi.Database.CreateApplicationDbConnInfo(si).
Access the dataset: Dim dt as DataTable = dtDataSet.Tables(0) (its index based)
Import it: api.Parser.ProcessDataTable(...)
JackLacava
OneStream Employee
2 years agoGlobals are not really global, in the sense that they're not shared across the entire application - only between multiple runs of the same type of rule. So it might be working in your Dashboard Extender because you're using it across multiple Dashboard Extenders (or other Dashboard-related types of rule, it's a bit more vague there).
Correctly estimating the lifecycle of a global can be tricky. In practice, they are typically used in two situations:
- Transformation/Parser rules. Since they have to execute for hundreds or thousands of rows on each Import, it makes sense to cache as much as you can in global objects (typically setup actions or lookups).
- Calculation rules. Again, these can be run hundreds or thousands of times with each consolidation, so it makes sense to reuse as much as you can between runs.
Now, back to your problem. Custom Calculations are not meant to return values, they are meant to save values to the database; so if you want something back, ExecuteCustomCalculationBusinessRule is the wrong approach.
What you want to do is to have your method as a separate Function in the business rule:
Namespace OneStream.BusinessRule.Finance.MyBR
Public Class MainClass
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As FinanceRulesApi, ByVal args As FinanceRulesArgs) As Object
[...]
End function
' add another function to the class
Public Function GetDataTable() as DataTable
' do your thang here
[...]
return myShinyDataTable
End Function
End Class
End NamespaceNow you can execute it from elsewhere (note: you will have to add "BR\MyBR" in the Referenced Assemblies property of this other rule):
Dim myBr as new OneStream.BusinessRule.Finance.MyBR.MainClass
Dim myDt as DataTable = myBr.GetDataTable()Note that this doesn't stop you from using the function in the CustomCalculate section of the same rule, if necessary:
Case = FinanceFunctionType.CustomCalculate
Dim myDt = me.GetDataTable()(You'll probably want your function to actually accept some parameters - particularly the SI object, which you will need pretty much all the time. Note that you don't have a valid api object in Dashboard contexts, so you can't use that.)
Last but not least: you probably don't want to put this sort of method, fetching random data, in Finance rules. It's literally the job for which Dashboard DataSet were invented. Among other benefits, you can execute DDS calls from Parameters or Data Adapter, which allow you to preview your dataset very easily as well as wiring it effortlessly to widgets. If you're not familiar with them, I strongly recommend to look them up (there is a decent intro on the blog, but look https://documentation.onestream.com/release_8.1/Content/Design%20and%20Reference/Application%20Tools/Business%20Rule%20Types.html?Highlight=dashboard%20dataset as well) and move your DT-fetching code there - again, you can still reference it from other rules, including Finance ones.
Hope this helps.
- adykes2 years agoNew Contributor III
Hey Jack, thanks a ton for your response, it was very informative, especially regarding global variables and their shortcomings. Based on the responses I've received I now understand that using a global variable is not a good option for accomplishing what I'm trying to accomplish.
I understand what you are saying about using a referenced assembly to call functions in the finance BR from the connector BR. I did in fact try this, but we are using the finance rules api in the function, so I am not able to pass in the correct api since connector BRs use a different type of api. Unless there's a way to use the finance rules api in the function without passing it in via the parameter, I don't think it will be possible to implement your suggestion.
Finally, we are actually using the finance BR in conjunction with a data adapter - the data adapter calls a DDS BR that calls the finance BR function. Again, I believe this is because we need to use api functions in the generation of the datatable, which is not possible with the api object provided with a DDS BR (as far as I know). I mentioned in another reply my issues with trying to query the method command of the data adapter, but I believe that approach would be more closely aligned with what you are saying.
Anyways, thanks for your response (and your helpful presence in the community). Final question - is "thang" official OneStream syntax? ๐
- JackLacava2 years ago
OneStream Employee
Yes, in a DDS you won't be able to use an api object of the same type as in a Finance rule (without contortions we don't want to go into).
I've read your other response, which mentions not having to rewrite the datatable-generating code, and I understand (although I'm pretty sure that, whatever it is that code does, it can be done without the Finance Api in one way or another. BRApi.Finance has pretty much everything you'd ever need...)
My suggestion then would be: in your Finance rule, you can dump your DataTable to an actual custom database table, which you can then read from elsewhere:
BRApi.Database.SaveCustomDataTable(si, dbLocation, tableName, dt, useBulkInsert)
You will have to manage the lifecycle yourself, though (checking if it exists already, and deciding when it's time to delete it or recreate it) - definitely not as quick as doing it in memory, but not too hard.
Worst of the worst: you can write it to a file, but it might be very slow (then again, it might be fast enough).
adykes wrote:
Final question - is "thang" official OneStream syntax? ๐
Ain't nuthin' but a Jack thang ๐ it's like this and like that and like this and uh...
- adykes2 years agoNew Contributor III
Yes, I'm aware that I could probably re-write whatever's in that finance rule with BRApis instead of apis, but I will gladly take the more simple approach of creating a custom database table, if it's possible (unsure yet if the application security settings will allow it). Do you know what functions I can use to delete it? I checked the BRApi available functions and am only seeing functions for saving the datatable.
Again, thank you so much for your guidance, and your lyrical genius :microphone:
Related Content
- 9 months ago
- 3 years ago