Referencing a custom structure from a referenced assembly

rhankey
New Contributor III

I am trying to figure out how to share a structure between OS BR files.

In an Extender BR file named ExtenderBR I have:

 

Public Structure MyStruct
	Public Element1 As String
	Public Element2 As Boolean
	Public Element3 As Integer
End Structure

Public Function MyFunct1() As String
	Return ""
End Function

Public Function MyFunct2() As MyStruct
	Return New MyStruct
End Function

 

In my Finance BR file, I include the BR\ExtenderBR from above and include a line

 

Dim ExtenderBR As New OneStream.BusinessRule.Extender.ExtenderBR.MainClass

Dim xx As String=ExtenderBR.MyFunct1()  'This works

ExtenderBR.MyFunct2() 'Generates error, as the Finance rule doesn't know about the custom Structure

 

Any thoughts how to share MyStruct across multiple OS Business Rules files?

1 ACCEPTED SOLUTION

It's just a namespacing issue. My code above worked because the type was not declared at compilation time, so typing information would only be (successfully) looked up at runtime; but yours wants types available at compilation time, so you have to import the namespace at the top:

Imports OneStream.BusinessRule.Extender.ExtenderBR.MainClass

That should solve your compilation issues.

(For the record, you don't need to mark "Contains Global Functions for Formulas" to go cross-rule, that option is just if you plan to actually reference it from the Member Formula properties on dimension members, something that typically only Finance rules concern themselves with.)

View solution in original post

4 REPLIES 4

JackLacava
Community Manager
Community Manager

#WorksForMe, dude, at least between Finance rules... I'd suggest to check for typos, there were a lot of them in the code.

JackLacava_0-1680189950566.png

JackLacava_1-1680189968845.png

 

 

rhankey
New Contributor III

I apologize if there were typos, or it appears I cut some corners in attempting to demonstrate the issue.  Below, I will show screen shots using the same hypothetical example.

Here is a screenshot of the relevant portion of the ExtenderBR that is to contain the common Structure & Function:

rhankey_0-1680196849835.png

And since you mentioned it might be an issue with using an Extender for the common Structure/Function, here's a screen shot of the same structure/functions replicated into a Finance Rule file too:

 

rhankey_2-1680197045964.png

And here is its properties tab showing that it has been tagged with having global functions:

rhankey_3-1680197113408.png

 

And now we move on to the Finance rule where I want to use the common structure and function.  In this rules file, I have included calls to both the common Extender and the common Finance rule file to kill two birds with one stone.  I have placed comments on lines 28:36 indicating the compiler issues I receive:

rhankey_6-1680197530384.png

 

And here is the properties tab:

rhankey_5-1680197336972.png

 

As I hope to have demonstrated above, there are no issues referencing the Public functions (and simple variables) defined in other BR files.  I do this sort of stuff a lot with no issue.  But I cannot reference custom structures defined in other BR files.

Any ideas how I can access a custom structure that I have defined in another BR file?

 

 

 

 

 

It's just a namespacing issue. My code above worked because the type was not declared at compilation time, so typing information would only be (successfully) looked up at runtime; but yours wants types available at compilation time, so you have to import the namespace at the top:

Imports OneStream.BusinessRule.Extender.ExtenderBR.MainClass

That should solve your compilation issues.

(For the record, you don't need to mark "Contains Global Functions for Formulas" to go cross-rule, that option is just if you plan to actually reference it from the Member Formula properties on dimension members, something that typically only Finance rules concern themselves with.)

rhankey
New Contributor III

I can confirm either of the following did resolve the issue.

Imports OneStream.BusinessRule.Extender.ExtenderBR.MainClass

or 

Imports OneStream.BusinessRule.Finance.FinanceCommonBR.MainClass

Thanks for the pointer.