Skip to content

Copy a Value to All Documents in a Batch

Legacy (Process Designer)

This page describes a script for the Modify Your Metadata activity of Process Designer. It was replaced by the Custom Step in Workflow. The script may not run as a Custom Step without changes. For new work, use the Custom Step reference.

If you have a value that might be populated by a cover sheet and apply to all documents in a batch, we have an example of using Modify Your Metadata to accomplish this.

If a batch has more than one document, get the value of the FirstName field from the first document in the batch. Then, copy that value to the FirstName column of all subsequent documents in the batch.

Full Script

if (batch.Documents.length > 1) {
    var originalDoc = batch.Documents[0];
    var firstNameValue = originalDoc.Metadata["Index"]["FirstName"];

    batch.Documents.forEach(function (doc) {
        if (doc != originalDoc) {
            builder.SetDocumentMetadata(doc.DocumentId, "Index", "FirstName", firstNameValue);
        }
    });
}

Walkthrough

  1. First, we will ensure the batch has more than one document.
if (batch.Documents.length > 1) {
  1. From there, we will take document 1, or 0 in the array of documents, and set it to a variable of OriginalDoc. From there, we will grab the FirstName field from that document and set it to firstNameValue.

        var originalDoc = batch.Documents[0];
        var firstNameValue = originalDoc.Metadata["Index"]["FirstName"];
    

  2. Then, we will cycle through each document that isn't originalDoc and set the FirstName field to firstNameValue in all documents within the batch.

        batch.Documents.forEach(function (doc) {
            if (doc != originalDoc) {
                builder.SetDocumentMetadata(doc.DocumentId, "Index", "FirstName", firstNameValue);