Example: Defining and Using Out Parameters with Workflows

Consider out-of-the-box factsheet generation workflow (which is one of two workflows that have been modified), and highlight the changes made to support and use out parameters. Map the output of one activity to the output of the workflow by defining out parameters and assigning values to them in intermediate activities.

Original workflow

This is the original factsheet generation workflow, where the translate activity generates a PDF (in $MQ_COMMON_DIR) that is output of the workflow.

<?xml version="1.0"?>
<!-- edited with XML Spy v3.5 NT (http://www.xmlspy.com) (Tibco) -->
<!--
Sample workflow for PDF fact sheet generation 
-->
<Workflow Version="1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Workflow.xsd">
   <Owner>TIBCO</Owner>
   <Name>wfin26productfactsheetpdfv2</Name>
   <Description>Sample workflow for generation of PDF data    sheets</Description>
   <Context>Sender</Context>
   <Parameter direction="in" name="inDoc" type="document"    eval="variable">1</Parameter>
   <Parameter direction="out" name="outDoc1" type="document"    eval="variable"/>
<!-- Edit loop -->
   <Activity Name="UpdateEventStartSync">
      <Start />
      <Action>UpdateEvent</Action>
      <Description lang="en">Update event state to indicate start of       workflow</Description>
      <Parameter direction="in" name="eventDescriptor" type="string"       eval="constant">FACTSHEET</Parameter>
      <Parameter direction="in" type="string" eval="constant"                 name="eventState">START</Parameter>
      <Parameter direction="in" name="InDocument" type="document"       eval="variable">inDoc</Parameter>
   </Activity>
<Activity Name="GetItemData">
      <Action>GetRecord</Action>
      <Description lang="en">Get record data</Description>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">GETPRODUCTINFO</Parameter>
      <Parameter direction="in" name="InDocument" type="document"       eval="variable">inDoc</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="Agency">SOURCE</Parameter>
      <Parameter direction="in" eval="xpath" type="long" name="MasterCatalog"       source="/Message/Body/Document/BusinessDocument/CatalogAction/CatalogA      ctionHeader/MasterCatalog/RevisionID/DBID/text()">inDoc</Parameter>
      <Parameter direction="out" eval="variable" type="document"       name="OutDocument">workDoc</Parameter>
   </Activity>
<!-- End of Add approval loop -->
<Activity Name="SetStatusToSuccess">
      <Action>UpdateEvent</Action>
      <Description lang="en">Set the event state to       Success/Done</Description>
      <Parameter direction="in" name="eventStatus" type="string"       eval="constant">SUCCESS</Parameter>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">DONE</Parameter>
   </Activity>
   <Activity Name="SetStatusToError">
      <Action>UpdateEvent</Action>
      <Description lang="en">Set the event state to Error/Done</Description>
      <Parameter direction="in" name="eventStatus" type="string"       eval="constant">ERROR</Parameter>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">DONE</Parameter>
   </Activity>
   <Activity Name="CreatePDFDataSheet">
      <Action>Translate</Action>
      <Description>Translate the record data to to PDF datasheet</Description>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">TRANSLATE</Parameter>   
      <Parameter direction="in" name="Derived" type="string"       eval="constant">true</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="Translator">XML2PDF</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="Map">standard/maps/mpfrom26topdfprodspecv1</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="OutputFormat">PDF</Parameter>
      <Parameter direction="in" eval="variable" type="document"       name="InDocument">workDoc</Parameter>
      <Parameter direction="out" eval="variable" type="document"       name="OutDocument">pdfDataDoc</Parameter>
   </Activity>
   <Transition FromActivity="UpdateEventStartSync" ToActivity="GetItemData"/>
   <Transition FromActivity="GetItemData" ToActivity="CreatePDFDataSheet" />
   <Transition FromActivity="CreatePDFDataSheet"    ToActivity="SetStatusToSuccess" />
   <Transition type="error" FromActivity="Any" ToActivity="SetStatusToError"    />
</Workflow>

Modified Workflow

This is the modified factsheet generation workflow, where you can define an out parameter at the workflow level, and in the Translate activity (used to convert the record date to a PDF datasheet), the outdocument is mapped to this out parameter.

<?xml version="1.0"?>
<!-- edited with XML Spy v3.5 NT (http://www.xmlspy.com) (Tibco) -->
<!--Sample workflow for PDF fact sheet generation -->
<Workflow Version="1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Workflow.xsd">
   <Owner>TIBCO</Owner>
   <Name>wfin26productfactsheetpdfv2</Name>
   <Description>Sample workflow for generation of PDF data    sheets</Description>
   <Context>Sender</Context>
   <Parameter direction="in" name="inDoc" type="document"    eval="variable">1</Parameter>
   <Parameter direction="out" name="outDoc1" type="document"    eval="variable"/>
<!-- Edit loop -->
   <Activity Name="UpdateEventStartSync">
      <Start />
      <Action>UpdateEvent</Action>
      <Description lang="en">Update event state to indicate start of       workflow</Description>
      <Parameter direction="in" name="eventDescriptor" type="string"       eval="constant">FACTSHEET</Parameter>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">START</Parameter>
      <Parameter direction="in" name="InDocument" type="document"       eval="variable">inDoc</Parameter>
   </Activity>
   <Activity Name="GetItemData">
      <Action>GetRecord</Action>
      <Description lang="en">Get record data</Description>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">GETPRODUCTINFO</Parameter>
      <Parameter direction="in" name="InDocument" type="document"       eval="variable">inDoc</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="Agency">SOURCE</Parameter>
      <Parameter direction="in" eval="xpath" type="long" name="MasterCatalog"       source="/Message/Body/Document/BusinessDocument/CatalogAction/CatalogA      ctionHeader/MasterCatalog/RevisionID/DBID/text()">inDoc</Parameter>
      <Parameter direction="out" eval="variable" type="document"       name="OutDocument">workDoc</Parameter>
   </Activity>
<!-- End of Add approval loop -->
   <Activity Name="SetStatusToSuccess">
      <Action>UpdateEvent</Action>
      <Description lang="en">Set the event state to       Success/Done</Description>
      <Parameter direction="in" name="eventStatus" type="string"       eval="constant">SUCCESS</Parameter>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">DONE</Parameter>
   </Activity>
   <Activity Name="SetStatusToError">
      <Action>UpdateEvent</Action>
      <Description lang="en">Set the event state to Error/Done</Description>
      <Parameter direction="in" name="eventStatus" type="string"       eval="constant">ERROR</Parameter>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">DONE</Parameter>
   </Activity>
   <Activity Name="CreatePDFDataSheet">
      <Action>Translate</Action>
      <Description>Translate the record data to to PDF datasheet</Description>
      <Parameter direction="in" type="string" eval="constant"       name="eventState">TRANSLATE</Parameter>
      <Parameter direction="in" name="Derived" type="string"       eval="constant">true</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="Translator">XML2PDF</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="Map">standard/maps/mpfrom26topdfprodspecv1</Parameter>
      <Parameter direction="in" eval="constant" type="string"       name="OutputFormat">PDF</Parameter>
      <Parameter direction="in" eval="variable" type="document"       name="InDocument">workDoc</Parameter>
      <Parameter direction="out" eval="variable" type="document"       name="OutDocument">outDoc1</Parameter>
   </Activity>
   <Transition FromActivity="UpdateEventStartSync" ToActivity="GetItemData"/>
   <Transition FromActivity="GetItemData" ToActivity="CreatePDFDataSheet" />
   <Transition FromActivity="CreatePDFDataSheet"    ToActivity="SetStatusToSuccess" />
   <Transition type="error" FromActivity="Any" ToActivity="SetStatusToError"    />
</Workflow>