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: IF command).

  • condition is required if the field expression (described below) is not used and not allowed if the field expression is used. There are several possible conditions but you can use only one at a time.
  • table.field (operator value-expression | IsChanging)
    • table is optional; however, if it is omitted, the Document Header (DocMasterDetail) is assumed. It specifies the target of the assignment. You can use @ to reference the current row in a FOREACH loop, or TargetRow to reference a recent row manipulated by another command such as ATC: ADD COMMENT or ATC: ADD ITEM.
    • . (period) is required only if table is specified. It separates table from field.
    • field is required. It specifies the field to be evaluated.
    • operator is optional but required with value-expression. Valid operators are
      • =
      • !=
      • >
      • <
      • IN or NOTIN
      • LIKE or NOTLIKE
    • value-expression is optional but required with operator. The value can be any of the following:
      • alphanumeric string
      • alphanumeric value-list is required with the IN operator. The value-list should be in the form A, B, C and can contain bookmarks.  See example.
      • [bookmark] specifies a Microsoft Word bookmark. The square brackets are required.
      • EMPTY indicates the field is empty
      • NULL indicates that the field has never been set.
      • LookupResult (dvname, value, dependson1, dependson2, dependson3) returns a value based on a scalar lookup (sort of like the Microsoft Excel VLookup function). See an example in ATC: SET.
        • dvname is the name of a lookup result. See the Lookup Result Validation Names section of  KBA-01535.
        • value is the value to look up, either a bookmark or a variable.
        • dependson1-3 are all optional and provide input values, either as bookmarks or variables
      • NOW () specifies that the current date and time is to be used.
        • +n.n can follow NOW () to add a number of days (with optional decimal) to the current date.
    • IsChanging is optional.  IsChanging is used in place of operator value-expression. It indicates that if the table.field has changed, the IF will be considered “true”.
    • IsEmpty is optoinal.  IsEmpty is used when you want to test if the value is DB NULL, a numeric zero or a string containing nothing except whitespace after HTML removal.  A zero length string is obviously empty too!

Example

ATC: IF DUE < NOW() + 14
     ATC: SET DocRevision.Notes=You have less than two weeks!
ATC: ELSE
     ATC: SET DocRevision.Notes=You have more than two weeks.
ATC:ENDIF

The example above means “if the due date is less than today plus 14 days, set the Note field to the message You have less than two weeks! Otherwise, set the Note field to the message You have more than two weeks.

ATC: IF DocDate IsChanging
     ATC: SET Title=Report for [DocHeader_DocDate]
ATC: ENDIF

The example above means “if the document date field changes, use the new document date in the document title, beginning with Report for; otherwise, do nothing.”

ATC: IF ProjectSubtype = CC
     ATC: SET Location = Downtown
ATC: ENDIF

The example above means “if the Project Subtype is equal to CC, set the Location on the document to Downtown; otherwise, do nothing.”

ATC: IF subtype IN FP, GMP
     ATC: SET Location = Contract Cap
ATC: ENDIF

The example above means “if the Subtype is equal to either FP or GMP,  set the Location on the document to Contract Cap; otherwise, do nothing.”

ATC: IF DocItem.Specification LIKE 16*   
     ATC: SET Location = Sounds Electrical
ATC: ENDIF

The example above means “if the first document item has a specification that begins with 33, then set the Location on the document to Sounds Electrical; otherwise, do nothing.”   See this handy reference about the LIKE operator.

ATC: IF UserHas WORK Staff  
     ATC: SET Location = The Staff Conference Room 
ATC: ENDIF

The example above means “if the current user has WORK Staff in any role, then set the Location on the document to The Staff Conference Room; otherwise, do nothing.”

See also the examples in ATC: ELSE and ATC: ENDIF.


Last updated: June 24, 2021 at 19:02 pm;  green text = new