- 16 Jan 2023
- 4 Minutes to read
-
Print
-
DarkLight
-
PDF
Switch/Case Statement Syntax
- Updated on 16 Jan 2023
- 4 Minutes to read
-
Print
-
DarkLight
-
PDF
Switch/case statements allow you to create complex condition statements. They check an asset field (declared in the switch) for multiple criteria (each declared by a case) and uses those values to populate the Action fields.
Syntax for Device Assets
Basic syntax for device assets:
switch device.adapters_data.adaptername.fieldname
case starts_with ("a") then form.form_field set_value "aaa"
case starts_with ("b") then form.form_field set_value "bbb"
case starts_with ("b") then form.form_field set_value "ccc"
Only assets matching the filter are affected using the matching value for the Action field.
Where
- switch - Configure the field on which to apply the filter defined by the CASE statements that follow.
- [device.adapter_data.adaptername.fieldname] - The source field of the Adapter (as displayed in the query bar). The device or user prefix must reflect the type of asset query. This value must be enclosed in brackets. For example, [device.adapter_data.adaptername.fieldname].NOTE
Adapter fields names must be written in brackets in the following format:
- [device.adapters_data.active_directory_adapter.hostname]
- [user.adapters_data.active_directory_adapter.username]
- [entity.<value pasted from query language>]
- case - Define the filter criteria.
- starts_with (" ") - The field name starts with the indicated text within the " ".
- Or one of the following operators:
- ends_with (" ") - The field name ends with the indicated text within the " ".
- not_starts_with (" ") - The field name does not start with the indicated text within the " ".
- not_ends_with (" ") - The field name does not end with the indicated text within the " ".
- contains (" ") - The field name includes the indicated text within the " ".
- field_equal (" ") - The field value is identical to the text within the " ".
- Or one of the following operators:
- then - then apply this value from the Adapter only to the assets whose field name starts with the value in starts_with.
- form_fieldname - The field name in the Action. See Using Syntax Helper below for instructions on how to find the correct field name.
- set_value - Tells the Action to set the value of form_fieldname to the value of the string that follows.
More operators and functions are available than are used in these examples. See Enforcement Action Condition Syntax Table for a complete list of available statement elements and their syntax.
Syntax for User Assets
Basic syntax for user assets:
switch user.adapters_data.adaptername.fieldname
case starts_with ("a") then form.form_field set_value "aaa"
case starts_with ("b") then form.form_field set_value "bbb"
case starts_with ("b") then form.form_field set_value "ccc"
Only assets matching the filter are affected using the matching value for the Action field.
Where
-
switch - Configure the field on which to apply the filter defined by the CASE statements that follow.
-
[user.adapter_data.adaptername.fieldname] - The source field of the Adapter (as displayed in the query bar). The device or user prefix must reflect the type of asset query. This value must be enclosed in brackets. For example, [user.adapter_data.adaptername.fieldname].
NOTEAdapter fields names must be written in brackets in the following format:
- [user.adapters_data.active_directory_adapter.hostname]
- [user.adapters_data.active_directory_adapter.username]
- [entity.<value pasted from query language>]
-
case - Define the filter criteria.
-
starts_with (" ") - The field name starts with the indicated text within the " ".
- Or one of the following operators:
- ends_with (" ") - The field name ends with the indicated text within the " ".
- not_starts_with (" ") - The field name does not start with the indicated text within the " ".
- not_ends_with (" ") - The field name does not end with the indicated text within the " ".
- contains (" ") - The field name includes the indicated text within the " ".
- field_equal (" ") - The field value is identical to the text within the " ".
- Or one of the following operators:
-
then - then apply this value from the Adapter only to the assets whose field name starts with the value in starts_with.
-
form_fieldname - The field name in the Action. See Using Syntax Helper below for instructions on how to find the correct field name.
-
set_value - Tells the Action to set the value of form_fieldname to the value of the Adapter field name that follows.
More operators and functions are available than are used in these examples. See Enforcement Action Condition Syntax Table for a complete list of available statement elements and their syntax.
Switch/Case Statement Examples
The following examples illustrate some ways Switch/Case condition statements can be used.
-
Example - Split the assets that match the query by the value of hostname, and use that value to determine the value of the email recipient.
switch device.adapters_data.active_directory_adapter.hostname case starts_with ("a") then form.emailList set_value "x@gmail.com" case starts_with ("b") then form.emailList set_value "y@gmail.com"
-
Example - Split the assets that match the query by the value of fieldA, and use that value to determine the value of the tag.
switch devices.adapter.fieldA case starts_with (“a”) then form.tag set_value “x” case starts_with (“b”) then form.tag set_value “y” case starts_with (“c”) then form.tag set_value “z”
For more information about working with Enforcement Sets see the following:
Enforcement Center Overview
Using the Enforcement Center Page
Managing Enforcement Sets
Creating Enforcement Sets
Testing an Enforcement Set
Configuring Enforcement Action Conditions
Scheduling Enforcement Set Runs
Running Enforcement Sets
Viewing Enforcement Set Run History
Terminating an Enforcement Set Run
Duplicating Enforcement Sets
Editing and Deleting Enforcement Sets