Skip to main content

compareFields

A Workflow Engine function that returns true or false based on the comparison of two string or number values.

An updated version of this function is available with the Add-ons v2.4 release. The updated version supports an “in” operator that expects a JSON array as the righSide argument. The function returns true if the leftSide is equal to any of the elements in the rightSide array.

You can use this function as an action in a workflow. The JavaScript localCompare() method compares the two strings. Both the left-hand and right-hand side are converted to lower case before comparison takes place. Valid operators are: >, <, >=, <=, !=, =. The = operator translates to the JavaScript strict equality operator === and the != operator translates to the strict inequality operator !==.

If the comparison returns true, then compareFields returns true. Otherwise, compareFields returns false.

If either the left-hand side or right-hand value of the comparison is null, then compareFields returns false.

Coercion takes place when one side of the comparison is a string of digits and the other side is a number. If coercion fails, then compareFields will return false. If the value for either side is not a number or a string, then compareFields will return false.

This function is available as a feature of the Add-ons v2.1 download and later. See Install Moogsoft Add-ons for information on how to upgrade.

This function is available for alert, enrichment, and Situation workflows.

The workflow sweep up filter applies to this function.

Back to Workflow Engine Functions Reference.

Arguments

Workflow Engine function compareFields takes the following arguments:

Name

Required

Type

Description

leftSide

Yes

String

The left-hand side of the comparison expression. A condition that can be evaluated to return a true or false value. This argument can be substituted.

operator

Yes

String

A binary comparison operator that takes two operands and returns true or false. Do not user quotes around the operator.

rightSide

Yes

String

The right-hand side of the comparison expression. A condition that can be evaluated to return a true or false value. This argument can be substituted.

Example

The following example demonstrates typical use of Workflow Engine function compareFields.

You want to increase the severity of an alert to critical if the value of custom_info.impact is greater than or equal to 1000. Create an Alert Workflow with a compareFields action and a setSeverity action. Set the following for compareFields:

  • leftSide: $TO_INT(custom_info.impact)

  • operator: >=

  • rightSide: 1000

The UI translates your settings to the following JSON:

{"leftSide":"$TO_INT(custom_info.impact)","operator":">=","rightSide":"1000"}

Example 2

As an example of using the ”in” operator, given the following:

  • leftSide: $(workflowContext.state)

  • operator: in

  • rightSide: ["closed","resolved"]

Which the UI displays as:

{"leftSide":"$(workflowContext.state)","operator":"in","rightSide":"[\"closed\",\"resolved\"]"}

The action would return true if workflowContext.state is equal either “closed” or “resolved.

When performing comparisons, if the leftSide is a number, then the elements in the rightSide array will be cast to numbers as required. If the leftSide is a string, the elements of the rightSide array will be stringified, as required.