Custom parameters are necessary to "extract" certain parts from the code and fill them in special fields without editing the code directly.
For example, if an API key is used in the code, you can generate a separate field in the JavaScript node for entering this parameter and reference it in the code. This way, when the API key changes, you only need to update the value in the separate field, not the code.
Below is an example code that counts the number of characters in the specified parameter.
/** @CustomParams{ "parameter2": { "type": "string", "title": "string_parameter", "required": false, "description": "Enter parameter", "options": { "minLength": 10 } }}*/export default async function run({ execution_id, input, data, store }) { // The input string parameter is obtained from the data object const String = data.parameter2; // Ensure parameter2 is a string if (typeof String !== 'string') { throw new Error('Parameter "String" must be a string.'); } // Count the number of characters in the string const characterCount = String.length; // Return the character count return { characterCount };}
Below is an example code that generates a random number not exceeding the value specified in the parameter.
/** @CustomParams{ "parameter3": { "type": "int", "title": "int_parameter", "required": true, "description": "Enter parameter", "options": { "max": 100, "min": 50 } }}*/import { randomInt } from 'crypto';export default async function run({ execution_id, input, data, store }) { // The input parameter MaxN is obtained from the data object. const MaxN = data.parameter3; // Ensure MaxN is a number. if (typeof MaxN !== 'number') { throw new Error('MaxN should be a number.'); } // Generate a random number from 0 to MaxN (not including MaxN). const randomNumber = randomInt(MaxN); // Return the generated random number. return { randomNumber };}
Below is an example that outputs the array specified in the parameter and the number of elements in it.
/** @CustomParams{ "parameter4": { "type": "string_array", "title": "string_array_parameter", "required": false, "description": "Enter parameter", "options": { "maxCount": 5 } }}*/export default async function run({ execution_id, input, data, store }) { // The input array parameter is obtained from the data object. const array = data.parameter4; // Ensure parameter4 is an array. if (!Array.isArray(array)) { throw new Error('Parameter "parameter4" must be an array.'); } // Count the number of strings in the array. const stringCount = array.length; // Return the count result. return { array, stringCount };}
Below is an example that identifies the highest value and its key from the list of values in the parameter.
/** @CustomParams{ "parameter5": { "type": "string_to_string", "title": "string_to_string_parameter", "required": false, "description": "Enter parameter", "options": { "maxCount": 2 } }}*/export default async function run({execution_id, input, data}) { // Ensure parameter5 exists and is an object. if (typeof data.parameter5 !== 'object' || data.parameter5 === null) { throw new Error('parameter5 is missing or not an object'); } // Initialize variables to store the maximum value and the corresponding key. let maxKey = null; let maxValue = -Infinity; // Iterate through all keys and values in the parameter5 object. for (const [key, value] of Object.entries(data.parameter5)) { // Convert the value to a number. const numericValue = parseFloat(value); // Check if the current value is the highest. if (numericValue > maxValue) { maxValue = numericValue; maxKey = key; } } // Return the maximum value and its key. return { maxKey, maxValue };}
The dropdown list parameter type is used to select a value from a predefined list of possible values. You can use the following options for this parameter:
options: an array like [{ "key": "SelectOptionKey1", "value": "SelectOptionValue1" }]. (value is the value that will be displayed in the dropdown list, key is the key that will be used in the code).