This video demonstrates developing a Flow Designer spoke and setting up an Automated Test Framework (ATF) test to automatically test its functionality
Linked time codes for these topics appear in the YouTube description for this video.
Watch these videos to help understand the basics of Flow Designer and ATF.
Let’s start with a quick introduction to spokes.
The flows and actions that you create in Flow Designer can be incorporated into spokes...
…which are scoped applications dedicated to a particular application or business process.
The base system provides some spokes that are active by default in the Now platform...
…and some that are activated by installing other ServiceNow applications, or purchasing apps from the store.
These spokes provide flows and actions for directly manipulating data in those applications.
With a subscription to IntegrationHub, you can also integrate with external instances and third-party applications via these spokes.
You may want to develop your own custom integration spokes, that you can share within your company or on the ServiceNow store.
Here’s an overview of the process.
The first step is to create a scoped application.
Scope uniquely identifies an app and its components, which are application files.
You can develop your scoped app right in a development instance, and move it between development, test, and production environments.
Here’s our use case.
We want to build a flow, triggered by this Service Catalog item...
... that will add a role to a user record after obtaining the necessary approval.
This functionality could be leveraged in a number of different applications.
Then we want to build a test in ATF that we can use to automatically test that functionality.
Here’s our Service Catalog item...
... with two variables set up for the user and the role.
Now we need to build a flow that we’ll specify here for the catalog item’s process engine.
So where do you build a Flow Designer or IntegrationHub spoke?
You do this using a scoped app in the Now Platform.
Studio is ServiceNow’s integrated development environment, or IDE...
... and is the preferred interface for building and modifying apps.
Here we create a new app to contain our Flow Designer content.
We can create app files of any type, including flows, actions, or connection and credential aliases in the Flow Designer.
All Flow Designer components saved into this app scope appear right here in the application explorer, whether or not we created them here.
Now let’s look at a feature in the Studio delegated development...
... which allows non-administrators to develop apps on the ServiceNow platform.
Administrators can specify which users and groups have access to Flow Designer app content...
... by assigning delegated development specific roles.
Let’s log in as this user to edit the flow.
This flow is to be triggered by a Service Catalog item.
For this functionality, you need the Flow Designer support for the Service Catalog plugin installed on your instance.
First we add an action to get catalog variables from the requested item record.
Then we select our template catalog item, so we can select the variables we want to use in our flow.
Now we add the action to request the approval.
We set up two rules.
Approve the request when the user’s manager approves…
… or reject the request when the user’s manager rejects it.
We’ve simplified this example, but in real life you’d also want to set up approval by an administrator for security.
We save our work so far...
…then add the final step, a flow logic component.
If the request is approved…
…then we add an action to create the record in the User Role table.
We select the fields in the table, and specify the catalog variables to populate the record.
Now we add the Else part of the If statement using a flow action component…
…where we create an action to log a message that the request was rejected.
We can add stages to the flow, so users can track its progress.
Finally, we test the flow in the Flow Designer to make sure it’s working.
Notice that we have to select a Requested Item Record to simulate the flow trigger.
The test pauses until we manually approve the request...
… and here’s the results.
We repeat the test, rejecting the request this time, to verify that the log message is created.
…and we’re good to go.
We can activate the flow.
Now we can add it to our Service Catalog item as the process engine, here in the Flow field.
The final step is to set up an automated test in ATF.
So why should you set up a separate test in ATF after testing the flow in the Flow Designer?
Because this allows you test other functionality that the flow is tied to in the platform...
... such as the Service Catalog item that serves as a trigger for the flow in our example.
Also, you can run the automated test in ATF any time after system modifications, upgrades, etcetera...
... to make sure the flow is still working as designed.
For the Name of the test we use the item name …
…and for the Description, we note what scenario this tests.
Now we’re ready to start adding test steps.
The first step in any ATF test should always be to impersonate a user with the roles needed to perform the steps in the test.
Next, we add a test step to open the item in the Service Catalog.
Now we need to set variable values for the form.
Because the request needs to be approved by the user’s manager, we select a test user with a known manager.
And we add the step to order the catalog item.
The Assert Type allows us to choose whether the item was ordered successfully or not.
For this test, we want the item to be successfully ordered.
Now we add a step to impersonate the user’s manager, the approver for the request.
Then we add a step to perform a record query, to verify that there is at least one record matching a query of the Requested Item table...
…where the request was opened by the user we impersonated...
... and that approval is requested.
This asserts that the authored flow was triggered, and the flow logic generated an Approval.
And finally, we add the last step to update the record by setting the state to approved.
We leave the Assert type as-is, …
…select the Requested Item table, …
…and choose the first record in the previous step’s record query to update.
Let’s run the test.
The test opens a client test runner...
... and we return to the previous tab to see the results.
For detailed test results, we go to the Test Results page.
We just tested and verified that this catalog item creates a user record when the request is approved.
Make sure to test all scenarios by creating separate tests for the behavior you expect in other situations, like these.
To test for log messages, note that you need to be capturing log messages in the log table, and then query the table.
An easy and efficient way to do that is to use Copy Test first, and then modify the test steps.
Now let’s take a quick look at collaborative development using source control.
The source control integration in Studio allows application developers to integrate with a GIT source control repository…
…to save and manage the development lifecycle of an app from a sub-production instance.
You can create a repository at github.com, or any other publicly accessible Git provider.
Linking an app to source control allows all application developers on a sub-production instance to collaborate on development.
Here are some proven practices we recommend when developing apps.
Add distinctive icons for your app to provide branding and visual differentiation between your app and other apps.
For apps that you will be sharing within your organization, you can add a logo in the application record...
…as well as a short description.
And the icon appears here in the Application picker in Flow Designer.
And finally, group your spoke content separate from existing apps.
By creating separate spokes for each individual type of functionality, you and other developers can leverage it for multiple uses.
And by keeping things separate, you also support a separation of responsibility for the code.
For more information, please consult our product documentation, knowledge base, or podcast.
Or ask a question in the ServiceNow Community.