> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/salesforce/forms/fill-fields.md).

# Filling PDF form fields

Learn how to access and fill form fields by their field id, iterate over all fields, and listen for field changes with this comprehensive guide. Salesforce WebViewer adds accurate, reliable document p

You can access and fill any form field by its field id:

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { documentViewer, annotationManager } = instance.Core;

documentViewer.addEventListener('documentLoaded', () => {
  documentViewer.getAnnotationsLoadedPromise().then(() => {
    const fieldManager = annotationManager.getFieldManager();
    const field = fieldManager.getField(fieldId);
    field.setValue('new value');
  });
});
```

{% endcode %}

[DocumentViewer.getAnnotationsLoadedPromise](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getAnnotationsLoadedPromise__anchor) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.getField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#getField__anchor) [FieldManager.setValue](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html#setValue__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { docViewer, annotManager } = instance;

docViewer.on('documentLoaded', () => {
  docViewer.getAnnotationsLoadedPromise().then(() => {
    const fieldManager = annotManager.getFieldManager();
    const field = fieldManager.getField(fieldId);
    field.setValue('new value');
  });
});
```

{% endcode %}

[DocumentViewer.getAnnotationsLoadedPromise](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getAnnotationsLoadedPromise__anchor) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.getField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#getField__anchor) [FieldManager.setValue](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html#setValue__anchor)
{% endtab %}
{% endtabs %}

## Iterate over all fields

You can also iterate over all fields using the [forEachField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#forEachField__anchor) function of FieldManager.

{% hint style="info" %}
Note that you'll need to wait for the [annotationsLoadedPromise](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getAnnotationsLoadedPromise__anchor) to resolve to ensure that the fields are accessible in the FieldManager.
{% endhint %}

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { documentViewer, annotationManager } = instance.Core;

documentViewer.addEventListener('documentLoaded', () => {
  documentViewer.getAnnotationsLoadedPromise().then(() => {
    // iterate over fields
    const fieldManager = annotationManager.getFieldManager();
    fieldManager.forEachField(field => {
      console.log(field.getValue());
      field.setValue('new value');
    });
  });
});
```

{% endcode %}

[DocumentViewer.getAnnotationsLoadedPromise](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getAnnotationsLoadedPromise__anchor) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.getField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#getField__anchor) [FieldManager.setValue](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html#setValue__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { docViewer, annotManager } = instance;

docViewer.on('documentLoaded', () => {
  docViewer.getAnnotationsLoadedPromise().then(() => {
    // iterate over fields
    const fieldManager = annotManager.getFieldManager();
    fieldManager.forEachField(field => {
      console.log(field.getValue());
      field.setValue('new value');
    });
  });
});
```

{% endcode %}

[DocumentViewer.getAnnotationsLoadedPromise](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getAnnotationsLoadedPromise__anchor) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [AnnotationManager.getFieldManager](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getFieldManager__anchor) [FieldManager.getField](https://sdk.apryse.com/api/web/Core.Annotations.Forms.FieldManager.html#getField__anchor) [FieldManager.setValue](https://sdk.apryse.com/api/web/Core.Annotations.Forms.Field.html#setValue__anchor)
{% endtab %}
{% endtabs %}

## Listening for field changes

The [fieldChanged event](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:fieldChanged__anchor) is fired any time the value of a form field changes.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { annotationManager } = instance.Core;

annotationManager.addEventListener('fieldChanged', (field, value) => {
  console.log(`Field changed: ${field.name}, ${value}`);
});
```

{% endcode %}

[AnnotationManager#fieldChanged](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:fieldChanged__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
// config.js
const { annotManager } = instance;

annotManager.on('fieldChanged', (field, value) => {
  console.log(`Field changed: ${field.name}, ${value}`);
});
```

{% endcode %}

[AnnotationManager#fieldChanged](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:fieldChanged__anchor)
{% endtab %}
{% endtabs %}


---

# 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.apryse.com/salesforce/forms/fill-fields.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.
