Bookmark and Share Share

Calling a Macro in a Mashup Script

Once you have defined macros or included a macro library in a mashup script, you call the macro in your mashup with a macro reference statement - an element with the macro name and the macro reference namespace.

For a macro named "myMacro", for example, the call to use the macro might look like this:

<macro:myMacro />

Note: examples of macro calls in this topic use macro as the prefix for the macro reference namespace.

See <macro:custom-macro-name> for details.

Macro Reference Namespace

Custom statements use a separate namespace from EMML because they are unique to your environment. They are not defined in the EMML schema.

When you use macros in a mashup, the macro reference namespace must be declared in your mashup script. See Declaring Namespaces for instructions. See EMML Namespaces for the current macro reference namespace.

Passing Input Parameters to the Macro

In most cases, you also need to pass in input parameters to the macro. Input parameters are defined as attributes on the macro reference statement with a name corresponding to the <input> declarations defined in the macro.

For example:

<macro name="myMacro"> 
  <input name="email" type="string"/> 
  <input name="message" type="string"/> 
  ... 
</macro> 
... 
<macro:myMacro email="myTeam@myOrg.com" message="$myMsg"/>

As with any EMML attribute, the attributes of the macro reference statement accept references to mashup variables or input parameters.

Receiving Macro Results

If the macro has results, the macro reference statement you use to call the macro also has an implicit outputvariable attribute that allows you use to identify the variable in your mashup script that should receive the macro results.

In the example shown below, the results of the macro are accessible inside the macro in the $macroResult variable.

<macro name="myMacroWithResults"> 
  <input name="email" type="string" /> 
  <input name="message" type="string" /> 
  <output name="macroResult" type="string"/> 
  <assign fromexpr="concat($message,', ',$email)" 
    tovariable="$macroResult"/> 
</macro> 
<macro:myMacroWithResults email="myTeam@myOrg.com" 
    message="Hello" outputvariable="myResults"/> 
<display message="Macro message is " variable="$myResults"/>

In this example, the macro results are placed in the $myResults variable identified in the outputvariable attribute when the macro is called.