Store Content in IDOL Server > Process Data before you Index > Use Lua Script Index Tasks > Process Documents with Repeated Fields

Process Documents with Repeated Fields
To help process documents with repeated fields, use findField to return multiple values. These can be assigned to different variables.
For example, this script:
function handler(document)
user1, user2 = document:findField("USERNAME")
document:addField("SECOND_USER", document:fieldGetValue(user2))
end
The script creates the field shown bolded below.
#DREREFERENCE document1
#DREFIELD USERNAME="mkgandhi"
#DREFIELD USERNAME="mgtyson"
#DRECONTENT
#DREFIELD SECOND_USER="mgtyson"
#DREENDDOC
You can convert multiple values to a list using curly braces. The Lua pairs function allows iteration over a list.
For example, to capitalize each USERNAME field in a document, the script should follow this structure:
function handler(document)
for k, field in pairs({document:findField("USERNAME")}) do document:fieldSetValue(field,document:fieldGetValue(field):upper())
end
end