Simple math transform functions

  • Release version: Xanadu
  • Updated August 1, 2024
  • 4 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Simple math transform functions

    Simple math transform functions in ServiceNow enable you to perform fundamental mathematical operations on numeric data pills within flows. These functions require input data pills of types Array.Number, Array.Integer, or Array.Decimal to operate correctly. If an incompatible data type is used, the function will return the original input without transformation at runtime.

    Show full answer Show less

    These functions are essential for manipulating numeric data during flow executions, supporting calculations such as addition, subtraction, averaging, rounding, and more.

    Key Functions and Their Uses

    • Absolute Value: Returns the positive distance of a number from zero.
    • Add: Adds a specified value to the input number.
    • Average: Calculates the average of values in a numeric array.
    • Count: Counts elements in an array of any data type.
    • Divide: Divides the input number by a given parameter.
    • Max and Min: Identify the highest and lowest values in a numeric array.
    • Median: Finds the median value of a numeric array.
    • Multiply: Multiplies the input number by a specified value.
    • Power: Raises the input number to the power of a given exponent.
    • Round: Rounds a number based on digit position and conventional rounding rules.
    • Square Root: Calculates the positive square root of a positive number.
    • Subtract: Subtracts a specified value from the input number.
    • Sum: Sums all values in a numeric array.
    • To Fixed: Truncates a decimal number to a specific number of decimal places without rounding.

    Practical Considerations

    When using these functions in your ServiceNow flows, ensure you select the correct input data pill types to avoid runtime errors or unexpected outputs. For functions requiring parameters (like Add, Subtract, Multiply, Divide, Power, Round, and To Fixed), provide the parameter value to define the operation precisely.

    For example, applying the Round function with a parameter of 2 on the input value 194 results in 190, based on rounding rules applied at the specified digit position.

    Expected Benefits

    These simple math transform functions streamline numerical data manipulation within your flows, enabling automated processing such as aggregation, scaling, and formatting. This capability enhances your ability to integrate, calculate, and report on numeric data efficiently without external scripting.

    Use simple math transform functions to perform basic mathematical calculations on Number data pills.

    Simple math transform functions require an Array.Number, Array.Integer, or Array.Decimal input data pill. Make sure to use the correct input data pill type when applying simple math transform functions. If a simple math transform function is applied to an improper data type, the data is not transformed at runtime and the input value is returned instead. For more information on confirming your flow runtime values, see Test a flow.

    Absolute Value

    A mathematical function that returns the distance from zero for any real number. An absolute value is always a positive or zero value.

    Input data pill Output data pill
    Number, Integer, or Decimal Number as the absolute value of the input number
    Figure 1. Example
    • Input: -3
    • Output: 3

    Add

    Adds the given value to the input.

    Input data pill Parameters Output data pill
    Number, Integer, or Decimal Number to be added. Number as the addition of the input value by the parameter.
    Figure 2. Example
    • Input: 12
    • Parameter: 4
    • Output: 16

    Average

    Returns the average value of the elements in the input array.

    Input data pill Output data pill
    Array.Number, Array.Integer, or Array.Decimal Number as the average value of the input array.
    Figure 3. Example
    • Input: [10, 30, 20]
    • Output: 20

    Count

    Returns the number of elements in the input array.

    Input data pill Output data pill
    Array.Number, Array.Integer, Array.Decimal, Array.Object, Array.String, or Array.Boolean Number of elements in the input array
    Figure 4. Example
    • Input: [2, 10, 30]
    • Output: 3

    Divide

    Divides the input value by a given value.

    Input data pill Parameters Output data pill
    Number, Integer, or Decimal Number to divide the input value by. Number as the division of the input value by the parameter.
    Figure 5. Example
    • Input: 12
    • Parameter: 4
    • Output: 3

    Max

    Returns the highest value found in the input Array.

    Input data pill Output data pill
    Array.Number, Array.Integer, or Array.Decimal Number as the highest value in the input Array
    Figure 6. Example
    • Input: [1, -5, 20, 6]
    • Output: 20

    Median

    Returns the median value of elements in the input array.

    Input data pill Output data pill
    Array.Number, Array.Integer, or Array.Decimal Number as the median value of the input array.
    Figure 7. Example
    • Input: [10, 30, 15]
    • Output: 15

    Min

    Returns the lowest value found in the input Array.

    Input data pill Output data pill
    Array.Number, Array.Integer, or Array.Decimal Number as the lowest value in the input Array
    Figure 8. Example
    • Input: [1, -5, 20, 6]
    • Output: -5

    Multiply

    Multiplies the input value by a given value.

    Input data pill Parameters Output data pill
    Number, Integer, or Decimal Number to be multiplied. Number as multiplication of the input value by the parameter.
    Figure 9. Example
    • Input: 12
    • Parameter: 4
    • Output: 48

    Power

    Returns the value of the input value raised to the power of a given value.

    Input data pill Parameters Output data pill
    Number, Integer, or Decimal Number as the exponent of the power. Number as the power of input value to the parameter.
    Figure 10. Example
    • Input: 2
    • Parameter: 3
    • Output: 8

    Round

    A mathematical function that approximates a numeric value based on rounding rules and a digit position. The function rounds up by adding one to the digit to be rounded and then replacing all digits to its right with zeroes.

    Input data pill Parameters Output data pill
    Number, Integer, or Decimal Number of Digits - A positive integer specifying the position of the digit to be rounded starting on the left Number as the rounded value of the input number
    Figure 11. Example
    • Input: 194
    • Parameter: 2
    • Output: 190
    Note:
    The function uses the digit to the right of the parameter digit to round up or down. If the digit to the right has a value from zero through four, the function rounds down. If the digit to the right has a value from five through nine, then the function rounds up. If there is no digit to the right, then the function rounds down.

    Square Root

    A mathematical function that computes a positive number that when multiplied by itself produces the input value. The input value must be a positive real number.

    Input data pill Output data pill
    Number, Integer, or Decimal Number as the square root of the input number
    Figure 12. Example
    • Input: 16
    • Output: 4

    Subtract

    Subtracts the given value from the input.

    Input data pill Parameters Output data pill
    Number, Integer, or Decimal Number to subtract from the input value. Number as the subtraction of the input value by the parameter.
    Figure 13. Example
    • Input: 12
    • Parameter: 4
    • Output: 8

    Sum

    Returns the sum of all values in the input Array.

    Input data pill Output data pill
    Array.Number, Array.Integer, or Array.Decimal Number as a sum of all values in the input Array
    Figure 14. Example
    • Input: [1, -5, 20, 6]
    • Output: 22

    To Fixed

    Truncates a floating number to the specified number of decimal places.

    Input data pill Parameter Output data pill
    Number - Decimal number before truncation. Number of Digits - Number that specifies the number of decimal places to truncate. Number - Decimal number after truncation.
    Figure 15. Example
    • Input: 1.93456
    • Parameter: 2
    • Output: 1.93