ThingWorx Flow > Creating and Managing Custom Actions > Creating a Custom Action in ThingWorx Flow 8.4.x
Creating a Custom Action in ThingWorx Flow 8.4.x
Create custom actions in the ThingWorx Flow Settings page or in a workflow from the Custom tab in the Actions panel.
Complete the following steps to create a custom action:
1. To add a custom action to ThingWorx Flow, do one of the following:
From the ThingWorx Flow Settings page, go to CUSTOM ACTIONS, and click .
In the Workflow Editor, from the ACTIONS panel, go to the Custom tab, and click .
The Custom Action window opens.
2. In the Label field, enter a suitable name for your action. This is required.
3. In the code editor, edit the prepopulated template to write the code for the action. For details on how to define the various parts of the action, refer to Defining a Custom Action.
4. Click COMPILE. If there are errors in the code, they are highlighted in the code editor. After a successful compilation, all the input fields defined in the input section of the custom action appear in the left pane.
5. Click SAVE. The action is added to the list of available actions under the Custom tab of the Actions panel and can be dragged onto the canvas for use in the workflow.
Defining a Custom Action
A custom action is a Node.js JavaScript function that defines the action. When you create a custom action, a sample template is prepopulated in the code editor. Use this template as a starting point to build your custom action.
Number
Description
1
Use the require() function at the start of the code to import Node.js modules for use in the custom action. In the sample code, the action is imports the request module to make simple HTTP calls to third-party systems.
* 
To safeguard against possible misuse, only the following Node.js modules can be imported for use in custom actions:
assert, buffer, crypto, events, http, https, lodash, path, punycode, querystring, request, soap, string_decoder, url, ws, xml2js, zlib
2
this.id—Attribute that is used as a unique identifier for the custom action.
3
this.label—Attribute that specifies the name of the custom action.
* 
If you use this.label to set the title for the action, it automatically overrides the action label you entered in the custom action window.
4
this.input—JSON attribute that defines the input fields to display when configuring the action in a workflow. There are three JSON keys for which you need to assign values:
title—(required) Used internally as an identifier
type—(required) Used internally. The value for this key should always be set to object and should not be changed.
properties—required) A JSON attribute that defines the input fields and validation conditions, if any, that appear for the action. Each input field should have a unique key such as first_name and define values for the following items:
title—(required) The label that appears for the field such as First Name.
type—(required) The type of the field. Valid types are string, object, array, and any
description—(optional) A message that appears as a tooltip.
minLength—(optional) Specifies the minimum number of characters that must be specified.
* 
To make a field mandatory, set the value of minLength to 1.
5
this.output— A JSON attribute that defines the output fields that the action returns and makes available in the rest of the workflow. There are three JSON keys for which you need to assign values:
title—(required) Used internally as an identifier.
type—(required) Used internally. The value for this key should always be set to object and should not be changed.
properties—(required) A JSON attribute that defines the output fields. Each output field should have a unique key such as status and define values for the following items:
title—(required) The label that appears for the field, such as status.
type—(required) The type of the field. Valid types are string, object, array, and any.
6
this.execute—Function that defines the program logic that runs when the action is executed within a workflow. The function must define the following two function parameters:
input—A JSON object that contains the values of the input parameters at workflow execution time. The values can be referenced using the input field keys as defined in the this.input attribute of the action.
output—A callback function that must be called to pass the output values to the workflow. It indicates that the action is completed. The function is in the form callback(err,output):
err—Used to report any errors that may have occurred to the workflow. If no errors occur, then use null.
output—A JSON object with values for each of the keys defined in the this.output attribute of the action.
* 
If you migrate from ThingWorx Flow 8.4.x to ThingWorx Flow 8.5, custom actions that were created in ThingWorx Flow 8.4.x continue to work in ThingWorx Flow 8.5. You can add localization support for input and output fields of the custom action. However, you cannot localize the label of the custom action that was created in ThingWorx Flow 8.4.x.
Was this helpful?