> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/creating-a-script-manually.md).

# Creating a script manually

## Introduction

If you're experienced in creating scripts for Patchworks and know exactly how to achieve what's needed, you can jump straight into the code. With the `build & test` page in `manual` mode, you have a full code editor with an integrated test panel alongside:

<div data-with-frame="true"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fj2bknxeBVXDGBT2mr1aP%2FScreen%202%20-%20building%20a%20script.png?alt=media&amp;token=dd47a9a6-3523-4579-82fd-c462729c7cf2" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
If you'd prefer some help, toggle into `AI` mode at any time and ask the script assistant — see [Creating a script with AI](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/creating-a-script-with-ai).&#x20;
{% endhint %}

## The build & test page

The key elements of this page are summarised below:

| Element                | Summary                                                                                                                                                                                                                                                                                                                  |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Manual / AI toggle     | Switch between writing code yourself and [building with AI](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/creating-a-script-with-ai). You can move between the two freely — for example, generate a draft with AI, then fine-tune it by hand. |
| Version menu           | Choose which version of the script you're working on, or start a new version. The counter alongside shows how many of the available **10 versions** are used.                                                                                                                                                            |
| Code editor            | A full code editor with syntax highlighting and line numbers. The status bar shows the language and version you're editing, together with your cursor position.                                                                                                                                                          |
| Test inputs / Logs     | The integrated test panel — see [Testing scripts](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts).                                                                                                                             |
| Save / Save & continue | Save the current version. Saving does NOT deploy the script — see [Deploying scripts & managing versions](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/deploying-scripts-and-managing-versions).                                                                                 |
| Settings               | Open the script's settings to update basic details (such as the runtime version).                                                                                                                                                                                                                                        |
| Full screen            | Expand the editor to fill your browser window — see below.                                                                                                                                                                                                                                                               |

## Adding & editing script code

When your script is first created, the editor is pre-loaded with a starter template for your chosen [script type](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting#script-types) and language. The template documents the inputs your script receives and the output it's expected to return — for example, the JavaScript template for a `General` script:

javascript

```javascript
/**
 * Custom script — general-purpose transform over the flow payload.
 *
 * @param data
 * @param {string|null} data.payload the payload as a string|null
 * @param {Object} data.meta metadata key/value pairs
 * @param {Object} data.flow flow execution state; read/write flow variables on data.flow.variables
 * @returns {{payload: string|null, meta: Object, flow: Object, logs: string[]}}
 */
module.exports = async function (data) {
  return data;
};
```

Work on the template to build the script that you need. Whatever the script type, the standard inputs — [variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables), [flow variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables) and metadata — are always available to your script.

{% hint style="info" %}
&#x20;For sample scripts in all supported languages, see our [custom script examples](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/custom-script-examples-general).
{% endhint %}

## The full-screen editor

For longer scripts, click the expand icon (top right) to open the full-screen editor:

<div data-with-frame="true"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FRU6CzN9ptKzqSQsMYxmv%2FFull%20Screen%20Editor%20with%20test%20window.png?alt=media&amp;token=b3a439d8-f8fa-43bf-a8a3-23f3e69136f3" alt=""><figcaption></figcaption></figure></div>

Everything you need is still to hand — the manual/AI toggle, version menu, save, and a collapsible [test panel](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts) so you can run the script without leaving full-screen mode. Click the collapse icon to return to the standard view.

## Saving your work

When you're ready, save the script:

* `Save` — saves the current version and stays on the page.
* `Save & continue` — saves the current version and moves you on.

{% hint style="info" %}
Saving a version does not deploy it — nothing that's live is affected until you choose to [deploy](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/deploying-scripts-and-managing-versions). This means you can save work-in-progress as often as you like.&#x20;
{% endhint %}

Having saved your code, make sure you [test it](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts) before deploying.
