Diesen Artikel finden Sie hier auch in deutscher Sprache.

And yet another killer feature in BimlExpress and BimlStudio 2017: CallBimlScriptWithOutput!

This post implies, that you’re already familiar with CallBimlScript – if not, please read Cathrine’s post on it first.

CallBimlScript is (and has been) a great helper for a while when it came down to automate specific pieces of Biml. The big disadvantage was: Other than giving you Biml code, it could not really interact with the calling file.
That was an issue in many cases, especially when building complex frameworks but also in cases as simple as you needing to know how to handle the output path of a component returned by a CallBimlScript.

So far, there wasn’t much you could do but either replicate a lot of logic, parse the XML returned, use countless annotations or have many many different versions of your callee.

All of these options aren’t too appealing, right?

But: help is here! In addition to the known CallBimlScript, you can now use: CallBimlScriptWithOutput! It allows you to make use of a dynamic object to be returned by the CallBimlScript (in addition to the Biml code) which effectively means: you can return any kind of information back to the caller.

Let’s take a look at how it works. This example actually doesn’t return any useful Biml code (just some commented derived column) – you already know how CallBimlScript works. The important part are the last lines of the Caller and the Callee.

To get started, we just define a valid simple table using manual Biml:

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
	<Connections>
		<OleDbConnection ConnectionString="server=local" Name="MyConn"/>
    </Connections>
	<Databases>
		<Database Name="DB" ConnectionName="MyConn"></Database>
    </Databases>
	<Schemas>
		<Schema Name="dbo" DatabaseName="DB"></Schema>
    </Schemas>
	<Tables>
		<Table Name="MyFirstTable" SchemaName="DB.dbo">
			<Columns>
				<Column Name="Col1"></Column>
				<Column Name="Col2"></Column>
            </Columns>
        </Table>
    </Tables>
</Biml>

Now, to the fun part! As usual, you would have a caller and a callee:

<#@ template language="VB" optionexplicit="False" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
	<# Dim table = RootNode.Tables(0) 
	   	Dim customOutput #>
	<#=CallBimlScriptWithOutput("callee.biml", customOutput , table) #>

	<!-- Result from customOutput: -->
	<!--<#= customOutput.ColCount #> -->
	<!--<#= customOutput.Description #> -->
</Biml>
<#@  template language="VB" #>
<#@ property type="AstTableNode" name="tbl" #>
<!-- Biml Code being returned directly: -->
<!--<DerivedColumns Name="MyderivedCol">...</DerivedColumns>-->

<!-- CustomOutput gets populated to be passed back to Caller: -->
<# CustomOutput.ColCount =  tbl.columns.count 
   CustomOutput.Description ="Isn't this awesome?"
   CustomOutput.Cols = tbl.Columns #>

So before passing on the parameter(s) (here: just an AstTableNode) to the Callee, we define a dynamic object and pass it to the function.

Within the callee, we can now dynamically add properties to the CustomOutput (Attention: Within the callee, that name matters! Within the caller, you can call the object whatever you want it to be named).
Here, I just add some existing properties from the passed table as well as a static string but this could effectively be any information you want to be able to use in the caller.

Within the caller, we’re just returning those properties as comments but, of course, we could now work with them and define our subsequent steps in our Biml code based on their value.

Now isn’t that awesome?

And because it’s so amazing and because I know, that some of you still have not accepted that VB is so much nicer than C#… This is the same code again – in C#. But please don’t tell anyone, I did that:

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
	<# AstTableNode table = RootNode.Tables[0];
	   	dynamic customOutput; #>
	<#=CallBimlScriptWithOutput("callee.biml", out customOutput, table) #>

	<!-- Result from customOutput: -->
	<!--<#= customOutput.ColCount #> -->
	<!--<#= customOutput.Description #> -->
</Biml>
<#@ property type="AstTableNode" name="tbl" #>
<!-- Biml Code being returned directly: -->
<!--<DerivedColumns Name="MyderivedCol">...</DerivedColumns>-->

<!-- CustomOutput gets populated to be passed back to Caller: -->
<# CustomOutput.ColCount =  tbl.Columns.Count;
   CustomOutput.Description ="Isn't this awesome?";
   CustomOutput.Cols = tbl.Columns; #>

Any questions or comments? We’d love to hear from you at !

Further Information on Biml in English can be found on our English Biml Page.

Happy Biml’ing!