Transform functions

  • Release version: Xanadu
  • Updated August 1, 2024
  • 3 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 Transform functions

    Transform functions in ServiceNow enable you to manipulate data pill values without scripting. They allow you to reformat text, perform calculations, sanitize inputs for security, and convert complex objects to XML. These functions cover categories such as date and time, string manipulation, utilities, simple math, shell and SQL sanitization, and complex data serialization.

    Show full answer Show less

    Applying Transform Functions

    You apply transform functions when designing flows by selecting the f(x) icon on a data pill, choosing a transform from the available list, entering any required parameters, and applying it. Multiple transform functions can be applied sequentially to the same data pill, with the system processing them from top to bottom.

    The system automatically suggests relevant transform function categories for certain inputs, such as SQL statements in JDBC steps and shell commands in SSH steps, to help prevent injection attacks.

    Important Guidelines

    • Ensure transform functions are applied to valid data pill types matching the input; invalid types cause the transform to be skipped or errors if parsing fails.
    • Transformations create new runtime values per input without altering the original data pill, so apply transforms individually for each use of the same data pill across steps.
    • Only the final transformed value is visible in flow execution details, not intermediate results.
    • Testing flows and actions is essential to verify that transform functions produce expected outputs in runtime scenarios.

    Transform Function Categories and Use Cases

    • Date and Time: Recalculate or reformat Date/Time values, such as adding time offsets for time zone localization.
    • String: Modify or calculate string values, e.g., trimming whitespace before CMDB integration.
    • Utilities: Extract values from complex objects like arrays or maps.
    • Simple Math: Perform basic calculations on numeric data pills.
    • Sanitize Shell Arguments: Remove unsafe characters to prevent injection in shell script commands.
    • Sanitize SQL: Escape special characters to prevent SQL injection in JDBC steps.
    • Complex Data: Serialize complex objects into raw XML for use in REST request bodies.

    Limitations

    Custom transform functions are not currently supported; for custom logic, consider using Inline scripts within Workflow Studio.

    Transform data pill values without the need to write a script. Use transform functions to reformat text, perform mathematical calculations, sanitize potentially unsafe SQL statements, and serialize complex objects to raw XML.

    Available transform function categories include date and time, string, utilities, simple math, sanitize shell arguments, sanitize SQL, and complex data. Some examples of transform function uses include:

    • Trimming white space from a string before integrating it into the CMDB.
    • Adding days, hours, minutes, and seconds to a date or time to localize for a specific time zone.
    • Sanitizing SQL values to prevent injection as part of a JDBC step for an Integration Hub spoke.
    • Retrieving an appropriate value from a map of priorities that have equivalent values in a third-party database.
    • Transforming a complex object into raw XML as part of a REST step Request Body field.
    Note:
    Custom transform functions are not currently supported. For information on creating custom functions to transform Workflow Studio data, see Inline scripts.

    Applying a transform function

    You can apply a transform function to a data pill when you are designing or creating a flow. To apply a transform function, point or tab to a data pill and select the f(x) (function icon) icon that appears. Selecting the icon displays the Available Transforms list. Select the transform function that you want to apply to your data pill, enter information into any required fields, and select Apply. Your selected transform function appears in the Applied Transforms list.

    Applying a transform function to a data pill.

    Applying multiple transform functions

    You can apply multiple transform functions to the same data pill. The system applies transform functions sequentially from top to bottom as listed in the Applied Transforms list. For example, you can apply a String to Date transform function followed by the Add Time transform function.

    Viewing applied transform functions

    You can find out which transform functions are applied to a data pill by looking at the Applied Transforms list. When you are designing or creating a flow or action, point to or tab into the data pill and select the f(x) (function icon selected) icon. You can also view applied transform functions in the flow execution details.
    Note:
    The output values for applied transform functions are field values, not Display values.
    When a data pill is dropped into certain types of inputs, the system automatically suggests a transform function category that is related to the input. For example, the system suggests transform functions to escape special characters in SQL statements, prevent script injection in shell scripts, and validate API or operation requests. Currently, the system suggests transform function categories for these inputs:

    General guidelines

    Apply transform functions to valid types of data pills for the input
    Be sure to check the type of data pill for the input before applying a transform function. Applying a transform function to an invalid data pill type results in the system skipping the transform. An error also occurs if transform functions produce results that the system cannot parse. For example, when transforming a string into a date, the system throws an error if the transform does not produce a valid date.
    Confirm applied transform functions for multiple inputs with the same data pill
    A transform function creates a new value at runtime for a specific input, and does not change the original data pill. If you use the same data pill across multiple actions or steps, transform functions must therefore be applied to each individual input.
    View final transformed values in the flow execution details
    Only the final transformed value appears in the flow execution details, and not the value for each applied transform.
    Test transform functions to verify they produce expected results
    Make sure that your transform functions produce the expected runtime values for the data pills. For more information, see Test a flow and Test an action.