Community

Code Example - Iterating through elements of a repeating group or table

In many cases, you may need to use a script to perform actions with elements in a document definition. The following C# code example demonstrates how to access the fields within a repeating group or table. Due to the nature of the repeating group element, this code needs to be executed within the document definition events. This example uses the After Document State Changed event.

//After document state changed in doc def event handler

//Check that the document is recognized 2 = ST_Recognized
if
(ChangedStates.Has(2)) {
//Check if the repeating group element is not empty if (Document.Field(@"Document Section 1\RepeatingGroup").Items.Count > 0) {
//Initialize a string to do something later with the value

string txt = "";
//Iterate through the repeating group Items collection
foreach (IField f in Document.Field(@"Document Section 1\RepeatingGroup").Items)
{
//Set the value of the string 'txt' to the value of the field

txt = f.Field("FieldName").Text; } } }

While there are other ways to perform this task, this is very basic code for accessing a field within a repeating group using C#.

0

Comments

0 comments

Please sign in to leave a comment.