Code Tool
The Code Tool gives the ability to write custom Node.js code against the data in an integration. It also offers the ability to write a custom output schema, which can be useful to reshape the data for later on in an integration.
Incoming Data
- The Code Tool can use data:
- directly - the node prior to the tool
- indirectly - using selectors. This gives the ability to take data from any point previous in the integration.
Use cases
-
The Code Tool enables the user to write custom logic on their data in an integration. This provides the user with full control on the operation/operations performed
-
Defining a custom output schema. In some integrations, the shape of the data from the incoming connector might not be suitable for the target connector. The Code Tool can be used as an adapter in these types of scenarios
-
Transforming data - transforming data from one schema to another
Writing the code
-
Within the Code Tool, there is a code editor. From here, Node.js code can be written
-
When creating a Code Tool, the user is provided with some starter code
-
The body of the incoming source node data can be accessed using
ctx.data.body
-
Selector data can be accessed through
ctx.data.selectors.<selector_name>
Customising Output schema
The schema coming out of the Code Tool can be customised as shown below:
Defining Output Schema
This is useful in situations where the schema needs to be adapted for use later on in the integration.
Co-Pilot
AI has been built into the Code Tool to help speed up the process of using it to manipulate the data to the desired outcome. It can be used by going into Co-pilot mode:
Copilot Mode
Transform
- Similar to the usage of a transfomer , Co-Pilot can be used to help write code to transform the data from the incoming node to the schema of the target node
Transform
- Note that this expects the output schema to be the target nodes (not customised)
Custom Code
- As mentioned previously, the Code Tool can be used for manipulating the output schema. AI can be used to help with this.
In Co-pilot mode, the user can provide a prompt to what they want to achieve and click
Generate
. The AI will then go away, analyse the data it has available to it, understand the user’s requirements and then write code to carry out the requested task
Prompting
Testing the Code
-
Note - the board must currently be published to test the code within the Code Tool
-
Once the board has been published, the Code Tool can be tested. This can be done using any example data the user may have or alternatively using AI to produce dummy test data following the schema of the incoming data
Testing