Skip to content

Phase 4 — Export Data File

Time to complete: ~10 minutes

Overview: In this phase, you’ll extend the workflow created in Phase 3 by adding a Function that exports data from a service and writes it to disk. The result will be a workflow that exports the results from an API call to the Demo Ecommerce API and writes the output to an XML file.

Completed Phase 4 Workflow A view of the completed Phase 4 workflow.

Steps

  1. In this step, you will include a Function in your workflow that will write a data file to disk. Functions are utility methods that make it simple to execute common tasks associated with integration and data manipulation without code. To incorporate a Function in your workflow:

    • Click the Functions menu in the left-hand toolbar.
    • Enter writetopackage in the search box Search for a Function by keyword writetopackage
    • Drag the File Function labelled writeToPackage (InputStream, String, String, boolean) onto the Workflow editor for the MyFirstWorkflow workflow and drop it next to the Repeat node.
    • Connect the output arrow labelled then from the Repeat node to the input arrow of the node labelled Execute File.writeToPackage.
  2. Configure the Function by clicking the expand icon on its node. Input / Output Mapper for File Function

  3. Specify that the file should be exported as XML by double clicking on the data Input property, enter the value skuArrayWithStockAvailable.asXml(), set the Language to Groovy, then click Apply. Set expression for data property

  4. Specify the name and location of the file by double clicking on the file Input property, enter the value resources/sku.xml, set the Language to Plain Text, then click Apply. Set expression for file property

  5. Run your workflow to verify its output. To run your workflow:

    • Click the Run button in the workflow editor toolbar. Accept the defaults and click Run.
    • Expected output: A file called sku.xml containing the output from the GetAllEcommerceSku service located in the resources folder of the my-first-project package. Double click on the file to view the contents of the file in XML.

    The object below is a representative element of the list/array of SKUs saved:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    <skuId>1</skuId>
    <name>Chisel Wood 6mm</name>
    <productCode>SKU001</productCode>
    <productVariant1>Wood</productVariant1>
    <productVariant2>6mm</productVariant2>
    <price>13</price>
    <createdDate>2025-09-02T00:00:06+0000</createdDate>
    <modifiedDate>2025-09-02T00:00:06+0000</modifiedDate>
    <itemId>1</itemId>
    <stockAvailable>191</stockAvailable>
    
    XML file output from File Function

What’s next: In Phase 5 you’ll learn how to automate the execution of your workflow.