ATC: FOREACH table 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).
- 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: December 29, 2017 at 19:05 pm; green text = new