How to Use Script Testing to Perfect Your Scripts

Updated on by Susanna Fagerholm

Scripting is a wonderful way to add control over how data is handled and transformed as it moves through an integration. However, writing scripts can be a trial-and-error process, requiring adjustments before they work as expected. This makes script testing a vital step before applying scripts in a live workflow, as it can prevent unexpected errors, wasted API calls, and unnecessary delays.

To that end, Cyclr provides a Script Testing tool inside the platform where users can run their scripts in a controlled space. It’s a dedicated environment to test, tweak and refine custom JavaScript before introducing it into integrations or Custom Connectors.

We explored the Script Testing tool, to see how it works and how it can be leveraged for efficient data transformations.

What is the Script Testing tool?

Cyclr’s Script Testing tool can be found in the Cyclr console under “Connectors” and “Script Testing”. It’s designed to provide a space to test JavaScript functions outside of an integration cycle, to allow users to debug and refine their scripts.

Instead of relying solely on third-party tools like Postman, or simply modifying live data and hoping for the best, with this tool, users can confirm how the script behaves before adding it into a step in an integration workflow or introducing it into a Custom Connector.

Why use the Script Testing tool?

Testing scripts within a workflow can be cumbersome, especially when dealing with third-party APIs that have rate limits, authentication requirements, or complex response structures. 

Testing scripts in a dedicated environment unlocks:

  • Faster debugging: Run scripts in isolation without triggering API calls.
  • Reduced errors: Catch mistakes before applying scripts to workflows.
  • Efficient iteration: Quickly tweak and retest code until the desired transformation is achieved.
  • Resource savings: Avoid unnecessary API calls that consume time and quota.

By using the Script Testing tool, users can confidently implement scripts that transform, filter, or reformat data.

How to use the Script Testing tool

1. Access the Script Tester

To start testing scripts, navigate to Connectors > Script Testing in the Cyclr Console to open the Script Testing interface.

2. Prepare sample data

Before writing a script, users will need to input test data that represents the request or response they want to manipulate. This can be a real API response copied from a workflow or a manually crafted sample JSON or XML object.

To input test data:

  1. Click Global and paste the test object.
  2. Assign a name (e.g., method_request or method_response).
  3. Specify the data format (JSON, XML, etc.).

3. Add code

Enter the JavaScript function(s) in the left-hand pane of the Script Testing tool. These scripts can perform various data transformations, such as:

  • Extracting specific fields.
  • Formatting data into a required structure.
  • Combining or splitting data fields.

For details on the available functions and objects, visit our scripting documentation

4. Execute the script

Once the script is written, in the text box available above it:

  1. Specify the function to execute (e.g., after_action).
  2. Click the green Run button.
  3. View the output in the right-hand pane.

If the script executes successfully, the expected output appears in the right-hand panel. Continue to adjust the code and re-run it until the expected output is achieved.

5. Applying the script to a workflow

Lastly, once the script is tested and validated, it can be copied into a workflow step by:

  • Adding it under Step Setup > Advanced Settings for individual workflow steps.
  • Embedding it within Custom Connector scripts for global application.

Best Practices for Script Testing

When working with the Script Testing tool, using real-world test data will improve accuracy. Copying sample API responses directly from a workflow allows users to better replicate real conditions. 

Starting with small, focused changes makes it easier to track the effects of each adjustment. Testing the script with a variety of data sets, including unexpected values, can help identify potential issues before they arise.

Modular scripts are generally easier to maintain and reuse. If the script is becoming complex, consider breaking it into smaller functions that can be combined or adapted as needed. Taking advantage of the Script Testing tool to refine the code will save a lot of time by reducing the need to troubleshoot failed workflow steps.

Common Challenges and Solutions

Here are a few issues users might encounter when using the Script Testing Tool and how to resolve them:

My script produces no output.

  • Ensure a return true; statement has been added at the end of the function. Without this, Cyclr may interpret the script as incomplete.

My script runs but doesn’t change the data.

  • Confirm that the sample object matches the structure expected by the script. Pay special attention to field names and data types.

I received an error about missing data.

  • Verify that the test data has been properly assigned as a Global object with the correct name and data type.

Perfect Scripts with the Script Testing tool

The Script Testing tool in Cyclr makes it easier to write, test, and refine scripts before they impact live workflows. By offering a safe environment for testing JavaScript functions, it allows users to experiment, debug, and perfect their code before it affects live data.

Instead of making changes blindly and troubleshooting errors as they appear, users can test scripts in a controlled environment and ensure they behave as expected. Allowing teams to save time, reduce errors, and build more reliable workflows.

By testing their scripts first, users can confidently modify data without risking live workflows or wasting API calls. Whether the goal is to standardize data formats, filter responses, or handle errors, the Script Testing tool gives users a faster and safer way to get their scripts right.

If you’d like to see Cyclr and the Script Testing Tool in action join us for a live demo!

We host a live demo every Tuesday and Thursday so you can see Cyclr’s integration capabilities.

About Author

Avatar for Susanna Fagerholm

Susanna Fagerholm

Joining Cyclr in 2024, Susanna is an experienced Content and Communications Expert specialised in corporate account management and technical writing, with a keen interest in software, innovation and design.

Ready to start your integration journey?

Book a demo to see Cyclr in action and start creating integration solutions for your customers

Recommended by G2 users