---
title: "Script"
description: "Run scripts seamlessly in your workflows with this handler, utilizing document and workflow variables for optimal process integration. (Gitana 4.0)"
product: "Gitana"
version: "4.0"
url: "/documentation/gitana/4.0/engine/workflow/workflow-handlers/script"
---

# Script

Type: `script`

This handler lets you run a script based on the items in a workflow.

The `config` for this handler is as follows:

```
{
    "script": "my script",
    "mimetype": "optional script mimetype (javascript by default)"
}
```

When writing your script, you will have access to variables containing document and workflow data:

- `workflow` Current [workflow](/documentation/gitana/4.0/engine/templates/workflow.md)
- `workflowTask` - Current [workflowTask](/documentation/gitana/4.0/engine/templates/workflowTask.md)
- `workflowData` - Workflow metadata
- `documents` - Array of documents being processed by the workflow

Example: Simple Publish

The following script is used as part of the [Simple Publish](/documentation/gitana/4.0/engine/workflow/sample-workflows/simple-publish.md) workflow. It allows further scripts to know the most recent changesets associated with a workflow's documents, so that they can be reset to that version in the event the workflow is cancelled:

```
{
    "script": "workflowData.originalChangesetIds = {}; for (var i = 0; i < documents.length; i++) { workflowData.originalChangesetIds[documents[i].id] = documents[i].changesetId; }"
}
```

## See Also

- The [Execute Script](/documentation/gitana/4.0/engine/behaviors/actions/execute-script.md) action
