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

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

```
GET https://docs.apryse.com/salesforce/forms/fill-fields.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
