Function thinklet

The Function thinklet enables custom data transformations and computations using JavaScript. While built-in thinklets handle most tasks, the Function thinklet provides flexibility for complex data manipulation and workflow logic.

How it works

Add JavaScript code to the Function thinklet to transform data, generate insights and automate workflow decisions.

Use cases

Use the Function thinklet for:

  • Data transformation – Convert values, format data and compute new metrics.

  • Time calculations – Determine time differences and track durations.

  • Decision automation – Use computed outputs to drive conditional workflow logic.

If you are not familiar with JavaScript, describe your input parameters, desired outputs and required transformations to an AI assistant like ChatGPT, or use another LLM tool. It will generate the necessary code for you, making the process quick and effortless.

Configuring the Function thinklet

Simplify third-party integrations by converting raw data into meaningful formats to, for example, calculate the number of days between two dates, without using workarounds or external tools.

  • Name: Enter a unique name for the Function thinklet.

  • ID: The system generates the ID automatically based on the name.

  • Description (optional): Describe the purpose of the thinklet and what it does. This information is useful for other users of the workflow who may not be familiar with it.

  • Parameters: Select Add parameter to configure thinklet parameters that also become input parameters for the function logic.

    • ID: Define the input parameter ID. Validation logic does not allow you to enter any characters that are not supported by JavaScript.

    • Value: Set the corresponding parameter value—database value, output of another thinklet, global parameter or custom value.

  • Outputs: Select Add outputs to configure up to 5 outputs of the function.

    • Name: Enter a unique name for the desired output.

    • ID: The system generates the ID automatically based on the name.

  • JavaScript: Write JavaScript code that defines the function's logic based on the input parameters. The script should also define any outputs that contain the IDs of defined Outputs.

JavaScript code structure

// Access input parameters
const param1 = parameter_ID_1;
const param2 = parameter_ID_2;
// ...
const paramN = parameter_ID_5; // Up to 5 parameters

// Logic for transformations

output_1 = /* your logic here */;
output_2 = /* your logic here */;
// ...
output_5 = /* your logic here */;

// Output any results for troubleshooting
console.log("Name the output", output_1);

JavaScript code example

This code example shows how to implement a password expiration checker within the Function thinklet.

// Access the last password update date defined as parameter
const lastUpdate = new Date(parameter_update_date);

// Define password validity period (90 days)
const validityDays = 90;
const expirationDate = new Date(lastUpdate);
expirationDate.setDate(expirationDate.getDate() + validityDays);

// Get current date
const now = new Date();

// Calculate days left
const timeDiff = expirationDate - now;
const daysLeft = Math.ceil(timeDiff / (1000 * 60 * 60 * 24));

// Set outputs 
Days_to_change_password = daysLeft;
Already_expired = daysLeft <= 0;

// Output intermediate results for troubleshooting
console.log("Days left:", daysLeft);
console.log("Need to notify:", Already_expired);
```

Last updated

Was this helpful?