•Output Data and Workflow Tests
Workflows could return a value or not, depending on your purpose. For this example, you'll configure the workflow to return a value. If the desired quantity is available, you'll make a HTTP POST request creating a new order. After that you'll return an object with two fields: id
of the newly created order and a text message success
. Otherwise, if there are not enough units, you'll return not enough units
message and -1
value for an id
.
•Failed scenario
First, lets cover the case when there is not enough units.
- Drag & Drop the Setter node to the canvas
- Double click on the node to open the configuration settings
- Select Set up result types button
- Activate the Workflow returns a value switch
- Select plus button and change key value to
message
- Select plus button again, change key value to
orderId
and type tonumber
- Select Apply button
- Write the
not enough units
message in the text field message - Put
-1
to the orderId field - Change the node's name to FailedOrder for example
- Select Apply
•Create an HTTP POST query
- Drag & Drop the Connector to the Canvas
- Connect Rule node with the Connector node
- Double click on the Connector to open the settings
- Click on Create connector button
- Give a name to the HTTP request, e.g.
CreateOrder
- Select Create button and you'll be redirected to the HTTP query builder
- Enter the URL pointing to the orders resource.
- Change request type from GET to POST
- Open the Body tap and configure add two fields:
quantity
andproductId
with type number. - Save the request and select Test request button. For productId pass 30 and for quantity 5 for example.
- You'll see that Status is 201 Created which means that your order is created successfully. Also the API returned an
id
for the newly created order. - Select Build schema button, click on Save button and finally select a Return to OrderProduct link.
- Select
CreateOrder
connector from the dropdown and set the Node name, e.g.CreateOrder
- Select Apply
•Add Another Setter to Return Success Message
You've already configured the result schema, so you just need to set a different result.
- Drag & Drop the Setter node to the canvas.
- Double click on the node to open configuration settings.
- Write the
success
message in the message field. - Select Use variable from state button, click on Select field... and then select CreateOrder.productId. Learn more about input parameters form.
- Change the node's name, e.g PlacedOrder
- Select Apply.
•Test the workflow
- Select Test button, for
productId
enter 30, and for quantity 5 units - As expected the order was created. Select Details tab to examine in depth workflow execution.
- Now lets start another test with same
productId
, but with a much larger amount, e.g. 56