:SWITCH ... :CASE ... :OTHER ... :ENDSWITCH

Use the :SWITCH script statement to run different script lines based on the value of a variable. The variable represents a condition, and the :SWITCH block contains one or more :CASE statements. The case determines which statements to run when the variable has a particular value. Define cases for each value of the variable for which to process different statements.

Tip: Use :IF... :ELSE... :ENDIF statements to evaluate expressions when you have a single condition.

Syntax

:SWITCH Variable
:CASE Value1
[Statements]
[:CASE Value2
[Statements]
...
]

[:OTHER
[Statements]
...
]

:ENDSWITCH

Parameters

Notes:

Important! You can use the predefined variable &$PLATFORM# with this script statement. If you use this predefined variable in a generic Job object, you must also define the &AGENT# variable in your script. The generic Job object does not have a defined host when you create it, so the script returns an error if you do not specify the host. For more information, see Predefined Variables for System and Object Values.

Examples

The following example retrieves the current day of the week as a number. The script uses day of week number to conditionally start a specific Job on Mondays and Fridays only.

:SET &DATE# = SYS_DATE_PHYSICAL("DD.MM.YYYY")
:SET &WEEKDAY#WEEKDAY_NR("DD.MM.YYYY:&DATE#")

:SWITCH &WEEKDAY#

:CASE 1
SET &ACT#ACTIVATE_UC_OBJECT(JOBS.MONDAY, WAIT)

:CASE 5
SET &ACT#ACTIVATE_UC_OBJECT(JOBS.FRIDAY, WAIT)

:OTHER
: PRINT "No Processing."
:ENDSWITCH

The following script in a generic Job object defines conditions based on the platform that the Job is running on:

:SWITCH &$PLATFORM#
:CASE "WINDOWS"
! insert these lines in your script to determine if an error occurred
! @set retcode=%errorlevel%
! @if NOT %ERRORLEVEL% == 0 goto :retcode
!

:CASE "UNIX"
:OTHER
:ENDSWITCH

See also: