ATC: FOREACH table state BY sortfield WITH filter;

This command begins a block of commands that will repeat once for each row in the specified table (that matches the filter). The block ends with the ATC: ENDLOOP command.

  • table is required. It specifies the tablename (e.g., DocItem).
  • (Build 9257) state is optional and if specified must come before BY sortfield.  One of the following can be specified:
    • Added indicates that only added records should match
    • Deleted indicates that only added deleted records should match
    • Modified indicates that only added modified records should match
    • Unchanged indicates that only added unchanged records should match
  • sortfield is required. It specifies the field in the table and is used to control the order of rows in the loop (e.g., DocItemNumber).
  • WITH filter is optional but requires a semicolon (;) after it. It specifies a filter for limiting the rows to those that match.  Use .NET Data Expression syntax, For more information see the Data Dictionary and .NET data expression syntax.  Do not use [bookmark] references before v2017.  (See Example 3)

Example 1 – Items

ATC: FOREACH DocItem BY DocItemNumber
     ATC: SET @.Evaluation = P
ATC: ENDLOOP

The above example means “for each Item, based on Item Number, set the Evaluation field to P (Pending).”

Example 2 – Attendees

ATC: FOREACH DocMeetingAttendee BY AttendeeKey WITH Present;
ATC: SET @.Present = 0
ATC: ENDLOOP

The above example means “for each attendee, clear the ‘Present’ flag”.  Present normally defaults from “IsRegular”, but this script, when bound to the “First Save” event, overrides that default behavior.  Note that the BY clause is necessary because the WITH clause is used.  In this example, WITH saves some processing time by skipping attendees who are already not “IsRegular” and therefore do not have the Present flag set.

Example 3:  Current Route

ATC: EXIT WHEN status != R
ATC: FOREACH DocRoute BY UserKey WITH Sequence = PARENT.CurrentSeq AND Stage = PARENT.MaxStage;
   ATC: IF @.ResponseCode IsChanging
     ATC: IF @.ResponseCode = P
       ATC: SET Status = P
     ATC: ENDIF 
   ATC: IF @.ResponseCode = F
       ATC: SET Status = F
   ATC: ENDIF 
   ATC: EXIT LOOP
 ATC: ENDIF 
ATC: ENDLOOP

The above example means “exit the loop once the status is no longer equal to R (Review). Until then, for each routee in the current sequence that has a changed response code, if the new code is P (Pass), change the Doc Status to P and if the new code is F (Fail), change the Doc Status to F.”


Last updated: July 10, 2025 at 9:53 am; green text = new

Related Post

ATC: ELSEATC: ELSE

ATC: ELSE This command can be used for an IF/ELSE situation, with ATC: IF. It indicates the ATC commands to be used when the ATC: IF command evaluates to false.

ATC: TARGETATC: TARGET

ATC: TARGET tablename option This command sets the Target table row for subsequent ATC: IF and ATC: SET commands. tablename is required and denotes the table to be used (e.g. DocItem). option

ATC: ATTACH ASSEMBLEATC: ATTACH ASSEMBLE

ATC: ATTACH ASSEMBLE options  This command assembles all attachments that are flagged as Incl=Assemble (on the document’s Attachment tab) and attaches that assembled PDF file to the target document. options are optional.  There are several