> For the complete documentation index, see [llms.txt](https://docs.getint.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getint.io/getintio-platform/items-routing-scripting.md).

# Items Routing Scripting

Item Routing scripting lets you decide where Getint creates each synced item. The script reads the item that triggered the sync and returns the project and item type for its counterpart on the other side. Use it when items from one project need to land in different projects or item types based on their field values, such as the assignee.

{% hint style="info" %}
Item Routing scripts use **JavaScript (JS) syntax**. Getint runs the script before the item syncs because it must know the destination first.
{% endhint %}

### How to Access the Items Routing Code Editor <a href="#how-to-access-the-items-routing-code-editor" id="how-to-access-the-items-routing-code-editor"></a>

1. From your integration editor, click **Items Routing**.

<figure><img src="https://4106311246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MR6Z9V8zLATPQPOGSDf%2Fuploads%2FhyVt3cGUcJQvS3pB5C4q%2FItems%20Routing%20with%20Getint.png?alt=media&amp;token=f1056996-b697-453d-9070-f01b119db6b5" alt=""><figcaption></figcaption></figure>

2. The **Items Routing** panel opens with the visual route builder. Click **Switch To Code Editor** at the top of the panel.

<figure><img src="https://4106311246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MR6Z9V8zLATPQPOGSDf%2Fuploads%2F7tolFyVZf4u5pT2XofYO%2FClick%20Switch%20to%20Code%20Editor.png?alt=media&amp;token=ba793e49-4ec6-47c0-88b2-cfd8e406004b" alt=""><figcaption></figcaption></figure>

3. Enter your script and click **Apply**.

{% hint style="warning" %}
To sync many projects to many projects, configure **Items Routing** on both sides of the integration. Until both sides are set, the integration editor shows a warning.
{% endhint %}

### How Item Routing Works <a href="#how-item-routing-works" id="how-item-routing-works"></a>

Each Item Routing script belongs to one side of the integration and decides where that side creates items. The trigger object always comes from the opposite side.

For example, if you set Item Routing for the LEFT app:

1. `state.triggerObj` holds the item from the RIGHT app.
2. The script returns a `projectId` and `issueTypeName` that exist in the LEFT app.

### Required Return Value <a href="#required-return-value" id="required-return-value"></a>

The script must return an object with two non-empty properties:

* `projectId`: the ID of the target project.
* `issueTypeName`: the name of the target item type.

`return {"projectId": "10778", "issueTypeName": "Task"}`

{% hint style="info" %}
If either property is missing or empty, Getint can't route the item, and it won't sync correctly.
{% endhint %}

### Available Commands <a href="#available-commands" id="available-commands"></a>

#### State

```
state.triggerObj - main JSON object representing the item that triggered the script
state.trigger - alias for state.triggerObj
```

#### API

```
api.log(logLine) - write a log line to the execution result for debugging
api.getCounterpart(itemId) - get the single linked item (counterpart) for the given itemId
api.getCounterparts(itemId) - get all linked items for the given itemId
api.sync(integrationId, itemList) - trigger a synchronization for the provided list of items
api.unsync(itemId) - remove the synchronization link for the given item
api.getRunCacheData(cacheItemId) - get data stored in the execution cache
api.setRunCacheData(cacheItemId, object) - store an object in the execution cache
```

&#x20;

### Example: Route Jira Issues by Assignee <a href="#example-route-jira-issues-by-assignee" id="example-route-jira-issues-by-assignee"></a>

This script routes Jira issues to different projects based on the assignee's display name. Issues assigned to a user whose name contains "Marcin" go to project 10778, and issues assigned to a user whose name contains "Service" go to project 11405. Both are created as Tasks.

```
// 1. Access input data
var triggerObjectFromOtherSide = state.triggerObj;

// 2. Log execution
api.log("Processing routing for issue: " + triggerObjectFromOtherSide.key);

// 3. Logic
var assigneeName = state.triggerObj.fields.assignee.displayName;

if (assigneeName.indexOf("Marcin") !== -1) {
  return {"projectId": "10778", "issueTypeName": "Task"};
}

if (assigneeName.indexOf("Service") !== -1) {
  return {"projectId": "11405", "issueTypeName": "Task"};
}
```

### Checking Script Logs <a href="#checking-script-logs" id="checking-script-logs"></a>

Messages written with `api.log` appear in the **Run logs**. Getint resolves Item Routing before the sync starts, so the output belongs to the run rather than to an individual item sync.

{% hint style="info" %}
If you encounter any issues or need further assistance, contact our support team [here](https://calendly.com/d/cpws-jb2-8xx/demo-call-all-team).
{% endhint %}

<figure><img src="https://4106311246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MR6Z9V8zLATPQPOGSDf%2Fuploads%2F9OSEDBl869gRue9mQAwv%2FGetint%20Yellow%20Banner.png?alt=media&amp;token=9cc42142-6e48-4931-8fd5-cbf7dcf4cdc1" alt=""><figcaption><p><a href="https://calendly.com/d/cpws-jb2-8xx/demo-call-all-team
">Start your integration journey. Schedule a free consultation with our Getint Integration Expert today!</a></p></figcaption></figure>


---

# 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://docs.getint.io/getintio-platform/items-routing-scripting.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.
