> For the complete documentation index, see [llms.txt](https://docs.rulecube.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rulecube.com/v2.5/how-to-guides/create-a-workflow/working-with-documents-in-a-workflow.md).

# Working with documents in a workflow

Rulecube contains some specialized methods that you can use within a workflow to handle uploaded or generated workflow documents.

**Workflow\.getDocuments()**

Get all documents from the database that are related to the current workflow.

Returns a list of `WorkflowDocument`.

**Workflow\.getDocument(documentTypeName)**

Get a document from the database with the given `documentTypeName`.

The `documentTypeName` parameter should match one of the document types defined in the workflow Settings.

Returns a `WorkflowDocument`.

**Workflow\.getDocumentDataUri(documentTypeName)**

Get a document from the database as a `data URI`.

The `documentTypeName` parameter should match one of the document types defined in the workflow Settings.

Returns a `string`.

**Workflow\.saveDocument(documentTypeName, dataUri, fileName?)**

Save a document to the database. This is useful for when you want your application to generate a document and store it.

The `documentTypeName` parameter should match one of the document types defined in the workflow Settings.&#x20;

The `dataUri` parameter is the Base64 data URI of the document.

The `fileName` parameter is optional and defines the name of the file.

Returns `void`.

{% code fullWidth="true" %}

```javascript
// This assumes there is a Document Type defined in the workflow with the name 'MyDocument'.' 
Workflow.saveDocument('MyDocument', 'data:text/plain;base64,SG93ZHkgcGFydG5lciE=');  

// The 3rd parameter is optional and can be used to set the file name. 
Workflow.saveDocument('MyDocument', 'data:text/plain;base64,SG93ZHkgcGFydG5lciE=', 'MyFile.txt'); 

```

{% endcode %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rulecube.com/v2.5/how-to-guides/create-a-workflow/working-with-documents-in-a-workflow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
