Testing a non-running flow with sample data

While developing a flow in the flow editor, you can use sample data to test the mappings and transformations that you specify in the input fields for the configured nodes. You can also test (or try out) the effect of an action on its target application, or test (try out) the entire flow. This capability helps you verify the correct behavior of the flow before you deploy it for general use.

About this task

Testing the mappings and transformations of your data input within fields

You can use auto-generated or custom sample data to test the mappings and transformations that you specify in the input fields for the nodes in a flow.

Tip: Testing a field's mappings and transformations affects only the sample data that is shown under the field in the flow editor; for example:
Sample data under a field showing values from test data

Procedure

To use sample data to test the mappings and transformations in your input fields, complete the following steps:

  1. From the flow editor, open the Context and sample data pane, which provides the facility for specifying sample data. You can open this pane in several ways:
    • Click the Context and sample data icon Context and sample data icon to the right of the event name, action name, or Request, Response, or Toolbox node name.
      Context and sample data icon for a node
    • Click within a field that contains a mapping, and then click the Edit link that is next to the sample data under the field.
      Context and sample data icon for a field
    • Click any mapping within a field, and then click Edit sample data from the menu, as shown in the following examples.
      Edit sample data option for a single mapping in a field
      Edit sample data option for a mapping within a transformation in a field

    When you click the Context and sample data icon Context and sample data icon for an event, action, Toolbox, or Response node name, the Context and sample data pane initially opens with a collapsed section for each of the previous nodes in the flow. In the case of a Request node, the collapsed section shows the input for the request. You can click to expand each section to view, regenerate, or customize the sample data for the fields. (The initial sample data typically displays a value of SampleFieldName for string fields, 1 for integer fields, true for Boolean fields, and 1985-04-12T23:20:50.52Z for date fields.)

    Context and sample data pane - opened for a node

    When you click within an input field and then click the Edit link for its sample data, the Context and sample data pane opens with a focus on the sample data for the first mapping in the input field.

    Context and sample data pane with the sample data field selected for the first mapping - opened by clicking the Edit link for a field

    When you click a mapping within an input field and then click Edit sample data from the menu, the Context and sample data pane opens with a focus on the sample data for the selected mapping.

    Context and sample data pane with the sample data field for the selected mapping - opened by clicking the Edit sample data option for a field
  2. In the Context and sample data pane, either manually specify one or more values that you want to use to test your field mappings and transformations, or click Regenerate sample data to auto-generate a fresh set of sample data. If the auto-generated sample data is not a perfect match for the type of data that you require, you can tweak this data to match your expectations.

    Changes that you make to the sample data in the Context and sample data pane are reflected in real time in the sample data that is displayed for the fields in the current node (and in any later nodes that reference those mappings). These changes will persist while the flow editor is open.

  3. To see the result of your changes to the sample data, look at the sample data under the node's input fields. If you've applied JSONata functions to the mapping, the sample data is transformed to show the result of those functions.

    The following example shows results for auto-generated sample data.

    Results for auto-generated sample data

    The following example shows results for custom data that was manually entered in the Context and sample data pane.

    Results for manually entered sample data

    After specifying sample data, you can close the Context and sample data pane by clicking the Close icon (x) or by clicking the Context and sample data icon again.

    Location of the Close icon and Context and sample data icon

Trying out an action on its target application

To test the effect of an action on its target application, invoke the action with sample data and then review the test results that the application returns.

Attention: Testing an action in this way attempts to complete the action on the target application that you are connected to. Before testing, verify that the account you've selected for the action is appropriate for testing use. If needed, you can select one account for testing and then after verifying that the test was successful, you can select another account to use when deploying the flow.

About this task

You can test the following actions in your flow:

  • All actions for applications that you have created accounts for on the Applications tab of the App Connect catalog; for example, Salesforce / Create lead
  • Any API that you have connected to on the APIs tab of the App Connect catalog
  • The Log utility on the Toolbox tab

To test an action, ensure that the following conditions are met:

  • For actions that require an account, ensure that an appropriate account is connected; for example, your Salesforce developer account.
  • Make sure that the configured action has no validation errors, such as missing required fields.

When these conditions are met, the Try this action icon Try this action icon is enabled:

Try this action icon in an enabled state:

Procedure

To test your specified settings for an action, complete the following steps:

  1. Specify realistic sample data for the type of action:
    1. Open the Context and sample data pane, as described in Testing the mappings and transformations of your data input within fields.
    2. Overwrite the default sample data with preferred custom values that you want to use for testing your mappings and transformations. Alternatively, click Regenerate sample data to auto-generate a fresh set of sample data and then tweak the values if required.
      Tip: Ensure that the sample data is appropriate for the type of action that you are testing. For example, if you are trying to retrieve data by using an ID or email address, the sample data must provide a valid ID or email address that exists in the target application. Or if you are trying to create a record, the sample data must match any special format that the target application requires for certain fields; for example, an email address of abc@xyz.com rather than SampleEmail.
  2. When you are satisfied with the results of the sample data that is shown under the fields for the action, click the Try this action icon Try this action icon.
    Eventbrite / New attendee event to Salesforce / Create lead action with edited sample data

    When the action is completed, a test result notification is displayed under the action name in the flow editor; for example:

    Test result notification for a successful test
  3. To see the test result details that were returned from the application, click View details to open the Test results pane. The results are displayed on the Output tab as shown in the following example. (You can also click the Input tab to see the content of the request.)
    Salesforce / Create lead action test success result

    In the Test results pane, you can click the Code icon (</>) to see the JSON output for the test and can copy this output by clicking the Copy icon Copy icon.

    JSON output for a successful test

    For the preceding example, which resulted in a successful test for a Salesforce Create lead action, you should also be able to see the new lead in your Salesforce instance. (This is why it is important to use test or non-production instances when trying out an action or flow.)

    Successful test results in Salesforce for a Create lead action

    If an action fails with an error when invoked on its target application, the test notification will show a "failed" result, and the details will provide more information; for example:

    Salesforce / Create lead action test failure result

Trying out a flow

After configuring all the nodes in a flow, you can test the effect of the flow on its target applications by using sample data and reviewing the test results that are returned.

Attention: Testing a flow in this way attempts to complete the actions on the target applications that you are connected to. Before testing, verify that the accounts you've selected for the actions are appropriate for testing use. If needed, you can select one account for testing and then after verifying that the test was successful, you can select another account to use when deploying the flow.

About this task

To test a flow, ensure that the following conditions are met:

  • For actions that require an account, ensure that an appropriate account is connected; for example, your Salesforce developer account.
  • Ensure that the configured nodes have no validation errors, such as missing required fields.
  • Ensure that the flow can be started (but isn't currently running).
    Message indicating that a flow can be started
    Restriction:
    • Flows that contain Batch process or Notification nodes cannot be tested.
    • A For each node will process only the first three items that it receives.

When the conditions for testing are met, the Try this flow icon Try this flow icon is enabled:

Try this flow icon in an enabled state:

Procedure

To test your configured settings for a flow, complete the following steps:

  1. Specify realistic sample data for the configured nodes in the flow by completing the following steps for each node:
    1. Open the Context and sample data pane for the node, as described in Testing the mappings and transformations of your data input within fields.
    2. Overwrite the default sample data with preferred custom values that you want to use for testing your mappings and transformations. Alternatively, click Regenerate sample data to auto-generate a fresh set of sample data and then tweak the values if required.
      Tip: Ensure that the sample data you want to test with is appropriate for its associated field. For example, if you are trying to retrieve data by using an ID or email address, the sample data must provide a valid ID or email address that exists in the target application. Or if you are trying to create a record, the sample data must match any special format that the target application requires for certain fields; for example, an email address of abc@xyz.com rather than SampleEmail.

    The following example shows the Request node of a simple flow for an API that retrieves contact details from Salesforce by ID. In the Context and sample data pane, the default sample data for the CustomerID request parameter has been overwritten with an actual contact ID from the connected Salesforce instance.

    Sample data for the Request node

    The Salesforce / Retrieve contacts action defines the retrieve by ID condition and indicates that the custom sample ID from the Request node will be used to make the call to Salesforce.

    Inherited sample data for the Salesforce / Retrieve contacts action

    The Response node defines the status code and contact data that should be returned for a successful response.

  2. When you are satisfied with the results of the sample data that is shown under the fields for the configured nodes, click the Try this flow icon Try this flow icon.
    Clicking 'Try this flow' to test a flow with sample data

    When the flow processing completes, a test result notification is displayed in the upper right of the area where the flow name is shown; for example:

    Test result notification for a successful test
  3. To see the test result details that were returned from the application, click View details to open the Test results pane. The results are displayed on the Output tab as shown in the following example. (You can also click the Input tab to see the content of the request.)
    Successful results for a 'Try this flow' test

    In the Test results pane, you can click the Code icon (</>) to see the JSON output for the test and can copy this output by clicking the Copy icon Copy icon.

    JSON output for a successful test

    For event-driven flows, your test results will show the following message on success: The flow test completed successfully. You can check the target applications to verify that you can see the expected results. Example:

    Successful results for a 'Try this flow' test for an event-driven flow

    If an action fails with an error when invoked on its target application, the test notification will show a "failed" result, and the details will provide more information. In the following example, a sample ID was generated to test the flow, which then resulted in a failure because that contact ID does not exist in the Salesforce instance.

    Test failure result for a flow

Example scenario

This example describes a scenario that causes App Connect to send a notification to members of a Slack channel when a new ServiceNow incident is raised. We want to apply some rules for notifications about new incidents, to give priority to incidents that require urgent attention.

  • If the incident is deemed to have a negative tone above some threshold, send a Slack message to notify the Site Reliability Engineering (SRE) team about the incident.
  • Otherwise, send the Operations team an email with details of the incident.

About this task

We can create a flow that uses IBM Watson® Tone Analyzer to analyze the tone of the new ServiceNow incident, to determine whether the incident is high priority. While developing the flow, we can use sample data to test individual actions and the entire flow to have confidence in the mappings and determine the tone thresholds that we want to use.

Procedure

  1. We trigger the flow with a ServiceNow / New incident event and then add an IBM Watson Tone Analyzer / Get tone analysis action. We configure the Text field in this action to specify which data should be analyzed from the ServiceNow incident. In this case, we want to analyze information that is recorded in the short description and comments, and so we add mappings for these ServiceNow fields.
    Event-driven flow with ServiceNow / New incident event and Watson Tone Analyzer / Get tone analysis action
  2. To add custom sample data that resembles the type of incidents that we want to analyze and determine a tone score for, we click within the Text field and then click Edit Context and sample data icon to open the Context and sample data pane. Here's an example of custom sample data that's likely to drive a negative score:
    Edited sample data for the ServiceNow / New incident event to be passed by data mapping in the Watson Tone Analyzer / Get tone analysis action
  3. To test this action, we click the Try this action icon Try this action icon, and then view the details of the (successful) test results to check the tone score returned from IBM Watson Tone Analyzer. For our sample data, we can see that the test generated mostly sadness and anger – tones that are generally associated with negative comments.
    Watson Tone Analyzer / Get tone analysis action test result

    We can perform further tests of the action to understand what is a good threshold to trigger a notification message in Slack.

  4. To define who needs to be notified in Slack, we add a Slack / Send message action and then specify a channel and the message text. We can also test this action with sample data to check that the Slack messages contain the right amount of information to help the SRE team investigate. Let's assume that the test is successful and we now want to test the entire flow.
    ServiceNow / New incident event to Slack / Create message action with edited sample data
  5. We click the Try this flow icon Try this flow icon beside the flow name and then view the test result details.
    Notification of a successful test for the flow

    We can see confirmation that the flow test was successful, and can check for the Slack message in the connected Slack account.

    Test results for the flow in the test pane and Slack