You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Purpose

  • The If Instruction is used for conditional processing in a workflow. It allows to check return codes and return values of previous jobs and it can be used to evaluate any order variables.
  • The If Instructions optionally allows to use an "Else" branch if the condition evaluates to false.
  • An If Instruction evaluates an expression that includes order variables and that results in a true/false value. The following basic use cases are suggested:
    • check the return code (exit code) of a previous job to decide which jobs or instructions to continue with,
    • check the return value (variables returned by a previous job) to decide about further processing,
    • check any order variables to determine the next instructions to process.
  • The If Instruction does not modify an order's state, however, if an If Instruction fails due to an error in the expression or syntax then the order is considered broken.

Syntax

  • The If Instruction evaluates an expression from a predicate and returns a Boolean value true or false.
  • Therefore Boolean algebra is applied, e.g. to evaluate expressions such as $returnCode.toNumber == 0.

Binary Operations

  • The If Instruction knows of two binary operations, which are "and" (conjunction) and "or" (disjunction) with the syntactical notation  && and ||.
    • The operations satisfy the following table 

      xyx && yx || y
      falsefalsefalsefalse
      truefalsefalsetrue
      falsetruefalsetrue
      truetruetruetrue
    • Round brackets should be used to group multiple expressions and to control the order of evaluation.
    • Conjunction beats disjunction if no grouping is used, i.e.
      •   x && y || z  is the same as (x && y) || z   
      •   x || y && z  is the same as   x || (y && z) 
    • Both operations using the basic elements true|false cover a number of algebraic laws such as associativity, commutativity and distributivity, for more details see Wikipedia.

Unary Operation

  • The If Instruction knows a single unary operation. This is "not" (negation) for which the notation is !.
    • The unary operation results in the following table:

      x!x
      falsetrue
      truefalse
    • A negation can be used for a single expression or for a group of expressions which are enclosed by round brackets.
    • The unary operation satisfies particularly De Morgan's law. i.e. 
      • !x && !y    =    !(x || y) 
      • !x || !y    =    !(x && y)

Strings

  • Strings can be either the value of a variable or an expression like "this is a string" or 'this is a string'.
  • Note that a string which is not the value of a variable needs quotation; either single quotes or double quotes.
  • If a single quoted string contains a single quote than this has to be escaped with a backslash, e.g. 'De Morgan\'s law'.
  • If a double quoted string contains a double quote than this has to be escaped with a backslash too.
  • (warning) An empty string has to use double quotes: "".

Variables

  • The predicate supports to check the value of job arguments and of order variables.
  • (warning) Variables support the following data types: string, number, boolean.
  • While an order passes a workflow any job can add or modify order variables.
  • A number of syntactical notations for variables are supported that give acccess to
    • the current value of a variable (maybe modified by a previous job),
    • the value that was returned by a specific JS7 - Job Instruction,
    • the original value of the variable as carried by the order.
  • (warning) If a predicate makes use of a variable that does not exists then the order stops with a FAILED state except that a default value has been specified for the variable. 

Workflow Instruction: If

Return Code Checking



Explanations:

  • x


Return Value Checking

  • Download Workflow Example: 


Variables Checking

  • Download Workflow Example: 




  • No labels