Some test text!

Search
Hamburger Icon

Salesforce / Guides / Fill form fiellds

Filling PDF form fields

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

// 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');
  });
});

Iterate over all fields

You can also iterate over all fields using the forEachField function of FieldManager.

Note that you'll need to wait for the annotationsLoadedPromise to resolve to ensure that the fields are accessible in the FieldManager.
// 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');
    });
  });
});

Listening for field changes

The fieldChanged event is fired any time the value of a form field changes.

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

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

Get the answers you need: Chat with us