> 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/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).

# 再利用可能なJSステップ（JavaScriptスニペット）

頻繁に使うJavaScriptのコードスニペットがある場合、Autifyに 「JavaScriptスニペット」を保存するとシナリオに挿入しやすくなります。

### &#x20;ワークスペースにJSスニペットを作成する

**ワークスペース設定** を開くと、**JavaScriptスニペット** というセクションがあります。JavaScriptスニペットはすべてここに保存されます。スニペットを新規作成するには、**追加** をクリックしてください。

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

&#x20;JavaScriptスニペットエディタが表示されます。まず、これから作成するスニペットに名前を付けましょう。

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

ここでは、後で再使用したいコードを入力します。コードは関数で囲ってありますから、エディタの中で関数を定義する必要はありませんが、必要があれば追加で関数を定義しても構いません。

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

&#x20;また、関数に引数を追加したい場合、括弧内の **＋** をクリックしてください。画面右側で引数の値を入力できます。引数を活用することで、よりダイナミックで柔軟なコードスニペットを作成できます。引数について詳しくは、Autify Universityの[JSステップ](https://help.autify.com/nocode-web/autify-university/advanced/js-steps/javascript-steps.md)をご覧ください。

{% hint style="warning" %}
**ご注意**

一度保存した引数の名前の変更と削除は、既存のシナリオを壊す可能性があり許可されていません。 引数の名前を変更または削除したい場合は、新たにJavaScriptスニペットを作成する必要があります。
{% endhint %}

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

&#x20;完了したら、画面下部の **追加** をクリックします。

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

### &#x20;テストシナリオにJSスニペットを挿入する方法

保存したスニペットは、**シナリオ詳細画面** から任意のシナリオに追加できます。まず、スニペットを挿入する位置で、ステップ間の **＋** をクリックします。次に、**スニペットからJSステップを挿入** を選択します。挿入したいスニペットを選んだら完了です。

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

&#x20;【重要】JSスニペットが特定の要素と作用する場合、ウェブページ上でその要素が利用可能になった時点にスニペットを追加してください。  スニペットを選択すると、テストシナリオにJSステップが挿入されます。他のJSステップと同様に、returnされた値を後続のステップで使用できるようになります。

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

### Autify JavaScriptスニペット

Autify の JS ステップでよく利用される JavaScript スニペットは[Autify JavaScript Snippets](https://javascript-snippets.autify.com/ja/)で提供しています。

各スニペットはテンプレートになっていますので、コードを適宜編集してご利用ください。

またご意見やご要望などありましたら、Autifyのチャットウインドウよりご連絡をお願いいたします！


---

# 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/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.
