When to use
- Execute reusable logic across multiple workflows without duplicating code
- Find specific elements in arrays from API responses
- Group data by key values for organization and reporting
- Encrypt sensitive data before sending to external systems
- Convert data formats (EDI, X12, cXML) for enterprise integrations
- Perform common operations without writing custom code each time
Input parameters
Dynamic input fields
When you select a function, input fields are automatically generated based on that function’s parameters. For example, selecting “Find element in array” displays:| Field | Description |
|---|---|
| array | The array to search through |
| element | The element to find |
Pre-defined library functions
Refold provides several pre-defined library functions that are available by default. These functions cannot be edited but can be used immediately in any workflow.Array Operations
Array Operations
| Function | Parameters | Description |
|---|---|---|
| Find element in array | array, element | Searches through an array to locate a specific element. Returns the index of the element, or -1 if not found. |
| Group objects by a key | array, key | Groups an array of objects by a specified key field. Returns an object with grouped arrays. |
Encryption
Encryption
| Function | Parameters | Description |
|---|---|---|
| Encrypt a string | string, password | Encrypts sensitive text data and returns the encrypted string. Provide an optional password to key the encryption. |
Date Helper
Date Helper
| Function | Parameters | Description |
|---|---|---|
| Get current date | format | Retrieves the current date and time in the requested format. Useful for timestamping records or calculating relative dates. |
| Convert date from one format to another | date, from_format, to_format | Transforms a date between format patterns. Supports patterns such as yyyy-MM-dd, MM/dd/yyyy, dd-MM-yyyy, dd MMM yyyy, and date-time patterns like yyyy-MM-dd'T'HH:mm:ssXXX and hh:mm a. |
| Extract date units | date | Parses a date to extract components like year, month, day, and hour. Accepts ISO, time-zone, JS, timestamp, and date-only formats. |
| Add/Subtract time | date, amount, unit | Adds or subtracts time from an ISO date. Supported units: seconds, minutes, hours, days, weeks, months, years. |
Miscellaneous
Miscellaneous
| Function | Parameters | Description |
|---|---|---|
| Generate UUID | none | Creates unique identifiers (UUIDs) for tracking, record linking, or external system integration. |
Math Helper
Math Helper
| Function | Parameters | Description |
|---|---|---|
| Math Operations | numbers, operation | Performs sequential arithmetic on a list of numbers. Supported operations: add, subtract, multiply, divide, modulus. |
Creating custom functions
Create reusable functions for your organization that can be called from any workflow.Write your function
Supported JavaScript libraries
The following npm modules can be used in your custom function code:| Library | Description |
|---|---|
| axios | HTTP client for API requests |
| cheerio | HTML parsing and manipulation |
| date-fns | Date utility functions |
| fast-xml-parser | XML parsing and building |
| fuse.js | Fuzzy search library |
| lodash | Utility functions for arrays, objects, strings |
| mime | MIME type detection |
| number-to-words | Number to text conversion |
| url | URL parsing utilities |
| uuid | UUID generation |
| danfo | Data analysis and manipulation |
Library usage examples
Using axios for HTTP requests
Using axios for HTTP requests
Using lodash for data manipulation
Using lodash for data manipulation
Using danfo for data analysis
Using danfo for data analysis
Output
The output structure depends on the function being executed. Each function returns its result in thebody field.
Find element in array (found)
Find element in array (found)
Find element in array (not found)
Find element in array (not found)
Custom function output
Custom function output
Error response
Error response
Adding to your workflow
Add the Functions node
Select a function
Configure input parameters
Configure custom output (optional)
Examples
Find Vendor in SAP Response Array
Find Vendor in SAP Response Array
| Field | Value |
|---|---|
| array | {{sap_get_vendors.body.vendors}} |
| element | {{webhook.vendor_id}} |
Group Invoices by Status
Group Invoices by Status
| Field | Value |
|---|---|
| array | {{netsuite_get_invoices.body.invoices}} |
| key | payment_status |
Encrypt Sensitive Vendor Data
Encrypt Sensitive Vendor Data
| Field | Value |
|---|---|
| string | {{vendor.bank_account_number}} |
Convert Purchase Order to EDI X12 Format
Convert Purchase Order to EDI X12 Format
| Field | Value |
|---|---|
| jsonData | {{purchase_order}} |
| transaction_type | 850 |
Troubleshooting
Function Not Found
Function Not Found
| Problem | Solution |
|---|---|
| Function not in dropdown | Verify the function exists in More > Functions. Check if it was created in the correct organization. |
| Function was deleted | Recreate the function or select an alternative function. Workflows using deleted functions will fail. |
Execution Errors
Execution Errors
| Problem | Solution |
|---|---|
| ”undefined is not a function” | Check the function code for syntax errors. Verify all required libraries are imported correctly. |
| Function returns unexpected output | Review the function’s input parameters and ensure values are passed correctly. Check the function code logic. |
| Timeout errors | Optimize the function code. Avoid long-running operations or external API calls with slow response times. |
Input Parameter Errors
Input Parameter Errors
| Problem | Solution |
|---|---|
| Required parameter missing | Refer to the function code in More > Functions to identify required parameters. |
| Invalid data type | Ensure input values match expected types (string, array, object). Use a Custom Code node to transform data if needed. |
| Dynamic variable not resolving | Verify the source node has executed successfully and the variable path is correct. |