Open topic with navigation

# Merge Document Fields

This script demonstrates how to merge the values of document fields.

When you extract data from a repository, CFS can produce documents that have multiple values for a single field, for example:

    #DREFIELD ATTACHMENT="attachment.txt"
    #DREFIELD ATTACHMENT="image.jpg"
    #DREFIELD ATTACHMENT="document.pdf"

This script shows how to merge the values of these fields, so that the values are contained in a single field, for example:

    #DREFIELD ATTACHMENTS="attachment.txt, image.jpg, document.pdf"

## Example Script

    function handler(document)
       onefield(document,"ATTACHMENT","ATTACHMENTS")
       return true;
    end

    function onefield(document,existingfield,newfield)
       if document:hasField(existingfield) then
          local values = { document:getFieldValues(existingfield) }
          local newfieldvalue=""

          for i,v in ipairs(values) do
             if i>1 then
                newfieldvalue = newfieldvalue ..", "
             end

             newfieldvalue = newfieldvalue..v
          end

          document:addField(newfield,newfieldvalue)
       end

       return true;
    end

© 2016 Hewlett Packard Enterprise Development LP | Send documentation feedback to HPE Close Send Documentation Feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to AutonomyTPFeedback@hpe.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_HP_HTML5_bannerTitle.htm