> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/reusable-js-steps.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Reusable JS Steps (JavaScript Snippets)

If there are JavaScript code snippets which you find yourself using often, you can save those custom snippets in Autify and insert them into any Scenario.

### Creating JS Snippets in your Workspace

In your **Workspace Settings**, you will find a section labeled **JavaScript Snippets.** This is where all of your saved JS snippets can be found. To create a new snippet, click the **Add** button.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-503a64cd7ad5dfac38382b67ca4553ba9f6eaa41%2Fadd-new-snippet.png?alt=media)

This will bring you to the JavaScript Snippets editor. You will first need to give a name for the Snippet you create.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-c941d093bc7f578dd9a7bebfa5ef2cd2d16b6b59%2Fjs-snippet-editor.png?alt=media)

From here, you can type the code that you would like to save for future use. The code is already wrapped in a function, so it is not necessary to define the function in the editor, but you can define additional functions as needed.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-6304c4d4834aaa1c6355288679589935d59aa81d%2Fjs-snippets-editor-code-block.png?alt=media)

You also have the ability to add arguments to your function by clicking on the **+** button within the parenthesis. You can then input the argument values on the right-hand side of your screen. Arguments make your code snippets much more dynamic and flexible. You can find more information on arguments in the [JS Steps](https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/javascript-steps.md) section of Autify University.

{% hint style="warning" %}
**Note**

Renaming and deleting arguments once saved is not allowed as it may break existing scenarios. If you want to rename or delete arguments, you must create a new JavaScript Snippet.
{% endhint %}

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-3f11bfe2e0d0e64d3f0b7a5dfc3fd5d1a2cd336e%2Fjs-snippet-code-editor-args.png?alt=media)

Once done, click the **Add** button at the bottom of the screen.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-8d6d88d10917060288aaf02eae7c675c576e0c0d%2Fjs-snippet-editor-add.png?alt=media)

### Inserting a JS Snippet into a Test Scenario

Once your snippet is saved, you can add it to any Scenario when in the **Scenario Details** page. To do so, click the **+** button between steps at the point you want to insert the snippet. Then select **Insert JS Step From Snippets.** And finally, select the snippet which you want to insert.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-dfccba578e33ce2708dd3d67f838ac522f3557e4%2Finsert-js-snippet.png?alt=media)

If your JS snippet is interacting with a specific element(s), it is important to note that you will want to add the snippet at the point where that element(s) is accessible on the webpage.

After selecting your snippet, the JS step will be successfully inserted into your Test Scenario. Just as with any other JS step, you have the ability to use the return value in subsequent steps.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-497d29fa7cc1b7cbefd47fe8ceaa4f3106acceb7%2FScreen%20Shot%202022-05-13%20at%204.35.03%20PM.png?alt=media)

### Autify JavaScript Snippets

[Autify JavaScript Snippets](https://javascript-snippets.autify.com/) is a library of commonly used JavaScript snippets created by Autify, and provided in the form of templates. Please feel free to edit and use them for your own needs.

If you have any opinions or requests regarding the library, please contact us via the Autify chat window!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/reusable-js-steps.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
