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.
A view of the completed Phase 4 workflow.
Steps
-
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 - Drag the File Function labelled
writeToPackage (InputStream, String, String, boolean)
onto the Workflow editor for theMyFirstWorkflow
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 labelledExecute File.writeToPackage
.
-
Configure the Function by clicking the expand icon on its node.
-
Specify that the file should be exported as XML by double clicking on the
data
Input property, enter the valueskuArrayWithStockAvailable.asXml()
, set the Language toGroovy
, then click Apply. -
Specify the name and location of the file by double clicking on the
file
Input property, enter the valueresources/sku.xml
, set the Language toPlain Text
, then click Apply. -
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 theGetAllEcommerceSku
service located in theresources
folder of themy-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>
What’s next: In Phase 5 you’ll learn how to automate the execution of your workflow.