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).
  • 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 should match
    • Modified indicates that only added modified should match
    • Unchanged indicates that only added unchanged 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: April 28, 2025 at 19:44 pm; green text = new

Related Post

ATC: SELECTATC: SELECT

ATC: SELECT option This command selects either the source document or the new document as the current document. Most commands affect the current document. option is required; however, only one

ATC: IFATC: IF

ATC: IF condition  | (table.field (operator value-expression |  IsChanging)) If this command appears anywhere in the script, the entire script is run in the background (even if the command is in an ATC: