1 Context:
This step entails building and setting up a workflow. We will build a simple version of a price query and will insert a button. This button will trigger the workflow, which will then call an external API, convert the response and output into a message on the screen. In order to do so we require a screen, which we will build in this exercise first.
2 Step by step guide:
- 👋 Navigate to “Design” -> “Screens” and select “Create” to create a new screen
- 👋 Fill in a “Name”
- “MyWorkflowScreen_<yourName>”
- “Description”
- “Smart-Module” -> “MyAppModule”
- “Template” type -> “Window (simple)” and select “Confirm”
- 👋 Now navigate to “Design” -> ”Components” -> “Forms”.
- 👋 Search in the “List of Forms” in the “Object Name” for “ItemForm”
- 👋 Mark it by clicking on the description and click on “Copy”.
- 👋 Fill in the name “ItemForm2_<yourName>” and save it to your module “MyAppModule”, then select “Confirm”
- 👋 Now navigate to “Design” -> ”Components” -> “Grids”.
- 👋 Search in the “List of repository objects” in the “Object Name” for the “ItemGrid”,
- 👋 Mark it by clicking on the description and click on “Copy”.
- 👋 Fill in the name “ItemGrid2_<yourName>” and save it to your “Smart-Module” -> “MyAppModule”, then select “Ok”
- 👋 Open the Screen Designer of your newly created screen and select the page in the “Preview” panel (Click on the blue bar where the name of the screen is displayed)
- 👋 Change the “Attribute Value” of “Layout” to “2E” in the “Attributes” panel and select “Save”
- 👋 Now populate the following objects (Using the ”Browse catalog of objects” panel) and connect them in the Flow Designer (select the third icon, called “Flow”, when hovered over, in the tab on the left) accordingly
- “ItemGrid2<youName>” -> “Panel A”
- “ItemForm2_<yourName>” -> “Panel B”
- “ItemDSO” → “Whole Screen, blue bar where the name of the screen is displayed”
- In the Flow Designer: “This Object” -(PrimarySdo)→ “ItemDSO” -(Data)→ ItemGrid2<youName> AND “ItemDSO” -(Display)→ ItemForm2<youName>
- 👋 Restrict the fields of the “ItemGird2” by first selecting the “ItemGrid2<youName>” in the “Preview” panel and then changing the “Attribute Value” of “instanceRestriction” to “!ItemName,!Itemnum,*” in the “Attributes” panel
- 👋 Open the Form Designer for the “ItemForm” by selecting the “ItemForm2_<yourName>” gear wheel in the “Layout” panel and then “Open Object Master”
- Design the form so that it looks like this:
- SimpleSwatBlock
- SimpleSwatNewColumn
- Remove not needed Attributes,
then select “Save”
- 👋 In the “Browse catalog of objects” panel search for the “SimpleSwatButton” and drag and drop it on the empty “SimpleSwatBlock” and click “Save” (There is currently a visualization issue. The button will appear after the safe)
- 👋 Select the “SimpleSwatButton” and set the following attributes in the ”Attributes” panel -
- “Enabled” -> Checkbox “True”
- “Label” -> “Check Market prices” Break point: Wait for the others to complete and present!
- 👋 Navigate back to the Home Screen. On the right panel click on the button “Launch Automation Hub” to go to the workflow area of Build.One
- 👋 A workflow window will appear. Click on the button “Start from scratch” to create a new workflow from scratch, then the editor appears
- 👋 Insert the following nodes. You can do that by clicking the plus icon in the top right corner or in the middle:
- 1. Webhook:
- Authentication: “None”
- HTTP Method: “POST”
- Path: “check-prices-<yourName>”
- Respond: “Using 'Respond to Webhook' Node ”
- Then select “Back to canvas” in the top left corner
- 👋 Click on the small plus sign next to your “Webhook” node to create the next part of your workflow
- HTTP Request:
- Method: “GET”
- URL: https://www.westmetall.com/api/marketdata/de/WM_Cu_high
- Authentication: “None”
- XML:
- Mode: XML to JSON
- Property Name: data
- Code:
- Mode: “Run Once for All Items”
- JavaScript:
const inputData = $input.last().json;
const prices = inputData.diagram.series.lineSeries.val;
const latestPrice = prices[prices.length - 1].y;
return { message: latestPrice };
This code is written in JavaScript and uses the variables inputData, prices, and latestPrice to extract and return the latest value from a JSON input data.
The inputData variable is assigned the value of the last JSON object from an input data source.
Then the prices variable is assigned the value of an array of price values extracted from the inputData JSON object. Finally, the latestPrice variable is assigned the value of the last price value in the prices array. The code then returns an object with a property message containing the value of latestPrice.
d. Respond to Webhook
- Respond With: “First Incoming Item”
- 👋 Your workflow should look like this. Set it from ⚠️”Inactive” to ✅“Active” & click on save in the top right corner:
Break point: Wait for the others to complete and present!
Now we will make the button, that we have previously created in our form on our screen, to the trigger for the workflow that we have just created
- 👋 Navigate back to the Screen Designer of your screen “MyWorkflowScreen_<yourName>”
- 👋 In the top “Ribbons” click on “</> Open event files” and go to Gitpod. In the source tree of your files a new event file should appear. The path is: /src/webui/clientlogic/_export/myapp/<Screenname>
- 👋 Fill in the following code and press “CRTL+S” to save your code:
interface Arguments {
context: Record<string, unknown>;
workflowName: string;
payload: Record<string, unknown>;
options: { isTest: boolean; }
}
export async function <YOURFUNCTIONNAME>(args: Arguments) {
const result = await window.akioma.automation.runWorkflow(args);
const message = { type: result.status, ...result.payload };
akioma.swat.Message.informationMessage (`The current price on the market is: ${result.payload.text} €`)}
--------------------------------------------------------------------------------------------------------------------
// Please delete the yellow spaces
//-> Note for <YOURFUNCTIONNAME>: Do not copy
//This is a function name please write it in the following syntax
//export async function checkPriceAlex(args: Arguments) {
//and delete the characters "<" and ">".
This code defines an interface named Arguments in TypeScript, which specifies the shape of an object with four properties:
context: A property of type Record<string, unknown>, which represents a key-value pair where the keys are strings, and the values can be of any type.
workflowName: A property of type string, which represents the name of a workflow.
payload: A property of type Record<string, unknown>, which represents a key-value pair where the keys are strings, and the values can be of any type and is intended to store data associated with the workflow.
options: A property of type { isTest: boolean; }, which represents an object with a single boolean property isTest.
This interface can be used as a type annotation to ensure that objects passed as arguments to functions or methods adhere to this specific structure.
This code defines an asynchronous function named “checkPricesYourName” that takes an object args as an argument, adhering to the Arguments interface, and is intended to be used for checking prices in a workflow.
The to const starts the workflow and saves the result
The message shows the result of the workflow in a small popup on the screen
- 👋 Navigate back to the Screen Designer. Open the Form Designer of your “ItemForm_<yourName>” and click on your button in the “Preview” panel.
- 👋 Search for the attribute -> “eventClick” in the “Attributes” panel and populate the “Attribute Value” with the following code (replacing the _<yourName> part in both cases) and select “Save”:
- 👋 Click on the code button. This will open the code editor.
#.checkPrice<YourName>({ context: { eventSource }, workflowName: 'check-prices-<yourName>', payload: {}, options: { isTest: false } })
--------------------------------------------------------------------------------------------------------------------
Note for the <function>: Do not copy
After the #. you should insert the function name that you have declared in the JavaScript class.
#.checkPricesAlex(
The workflowname should be called exactly as you have declared it in the webhook node in the workflow engine
check-prices-alex/
- 👋 Close the Form Designer and go back to your screen
- 👋 Click on your screen in the “Preview” panel (Click on the blue bar where the name of the screen is displayed) called “MyWorkflowScreen_<yourName>” and search for “Namespace” in the “Attributes” panel and fill the ”Attribute Value” with “#” and select “Save”
- 👋 Execute a hard reload and empty cache of your browser tab (Open the Browser Console by clicking F12 and hold with left click on the broswer reload until the options appear ) → The hard reload is needed because everytime the frontend was built (compiled and built), it will be saved into the browser cash in order to load faster. So if you have made changes in the frontend code, the displayed app in Build.One is still based on the old Frontend code. This means every time you change something in the frontend code, you need to compile it and empty the cash to rebuild the WebUI.
- 👋 Launch the screen and click on the button to see the message
- 👋 Navigate to gitpod and go to src/data/n8n/workflow.json and delete the workflow.json. (There is already one that exists, which B1 prepared for this training. We will replace this one with the new workflow now)
- 👋 In the terminal type in b1 export-automation
- 👋 Your new created workflow will appear in the folder. (Please put “ [ ] ” around your code because gitpod expects a JSON if it is not there). Right click on the code and select “Format document”
💡 To make you screen constantly available we need to export the workflow to gitpod
3 Explanation:
With this workflow example, we show how easy it is to connect an external API using visual tools. This task includes three components: