Design a Flow
Learning Objectives
After completing this unit, you’ll be able to:
- Prepare to design a flow.
- Design a flow to automatically sync data from ServiceNow to Salesforce to Slack.
In this unit, you first learn how to prepare to design your flow. Then, you learn how to use MuleSoft Composer to create a flow that automatically syncs incidents in ServiceNow with cases in Salesforce and notifications in Slack.
Prepare to Design a Flow
Recall from MuleSoft Composer Basics that a flow is a sequence of steps that you assemble and configure to integrate systems and data. Before designing a flow, you should map the tasks your flow must perform to their corresponding steps in the form of flow components. You can do this using paper and pencil so you can get a good idea of what your flow will look like.
Here’s an example of such mappings for the NTO use case described in the previous unit.
Task | Flow Components |
---|---|
Find any new or updated incident in ServiceNow. |
Trigger from ServiceNow |
Determine if a corresponding case exists in Service Cloud. |
Action step to get all cases in Service Cloud that have the same ServiceNow number. |
If a corresponding case doesn’t exist |
If/Else block evaluating if the list of cases is empty with these action steps in the If branch:
|
If a corresponding case exists |
Action steps in the Else branch of the If/Else block:
|
By default, MuleSoft Composer validates your work and provides contextual in-app help every step of the way. For example, when you add a connection to a system, MuleSoft Composer tests the connection to make sure it works before you can proceed to the next step. Also, to simplify building your flows, MuleSoft Composer prompts you to complete required fields within each step.
As a best practice, when building a flow, add a few steps and test iteratively until you complete the flow.
Take a look at this video demonstration showing how to connect ServiceNow to Salesforce to Slack using MuleSoft Composer.
Design a Flow
Now you’re ready to design an integration flow that syncs incidents in ServiceNow with cases in Salesforce and notifications in Slack.
Follow these steps to design a flow.
Launch MuleSoft Composer from the NTO org.
- Log in to your NTO org using your username and password.
- From the App Launcher, enter
Composer
and select MuleSoft Composer.
Create a new flow.
- Click Create New Flow.
- Click the pencil icon next to the default flow name.
- Name the flow
Sync Service Cases - ServiceNow to Salesforce to Slack
and click Save.
Create a trigger for the flow using the ServiceNow connection.
- Click ServiceNow.
- Click Add new ServiceNow connection.
Note: If this is your first ServiceNow connection, this option doesn’t appear. Go to the next step. - Using the text file that contains the ServiceNow connection parameter values, enter the required values with
NTO ServiceNow
as the connection display name, and then click Create. MuleSoft Composer automatically tests the connection. If no error message appears, you have a successful connection, and the first step (trigger) of the flow appears.
Configure the trigger to start the flow every time an incident is created or updated in ServiceNow.
- Click in the Choose an event that starts this flow field and select New / Updated Record.
- In the Table Name field, enter
incident
. - Click Save to save the flow.
Create the second step for the flow to get all cases in Salesforce that match the triggering incident.
- Click the plus icon to add a step.
- Click Salesforce.
- Click Add new Salesforce connection to create a connection to the NTO sandbox org.
Note: If this is your first Salesforce connection, this option doesn’t appear. Go to the next step. - Name the connection
NTO sandbox org
. - Select the checkbox This is a sandbox organization and click Create.
Note: If you use a developer org, skip selecting this checkbox and click Create. - Enter your NTO sandbox org’s username and password and click Log In to Sandbox.
- Click Allow to grant MuleSoft Composer the permissions to access the identity URL service, manage user data via APIs, and perform requests at any time. MuleSoft Composer automatically tests the connection. If no error message appears, you have a successful connection, and the second step of the flow appears.
Configure the second step to get all cases that match the incident.
- Click in the Action field and select Get records.
- In the Object Type field, enter
Case
. - In the Conditions to filter the objects picklist, select All conditions must be met (AND).
- Select ServiceNow Incident ID as the field, Equals as the operator, and Number from step 1 of the flow.
Create and configure an If/Else block to evaluate whether the incident has a Salesforce Case ID.
- Click the plus icon to add a step.
- Scroll down and click If/Else Block. The All conditions must be met (AND) condition is selected by default.
- Select List of Case from step 2 of the flow as the field and Is empty as the operator. If this condition is met, it means the incident doesn’t have a corresponding case in Service Cloud. So the next three steps in the If branch (create Salesforce case, update ServiceNow incident, and send Slack message) are executed.
Create the third step for the flow within the If branch to create new cases.
- Click the plus icon to add a step within the If branch.
- Click Salesforce and then click NTO sandbox org.
Configure the third step to create new cases in Service Cloud.
- Click in the Action field and select Create new record.
- In the Object Type field, enter
Case
. - Click Add Fields, select ServiceNow Incident ID, Status, and Subject, and then click Add.
- Map the Case fields in Service Cloud to their corresponding Incident fields in ServiceNow captured in step 1 of the flow as follows.
- ServiceNow Incident ID = Number from step 1
- Status = Click the search picklist, select Pick from List, and then select New
- Subject = Short_description from step 1
Create the fourth step for the flow within the If branch to update incidents with their associated Salesforce Case IDs.
- Click the plus icon to add a step to the If branch.
- Click ServiceNow and then click NTO ServiceNow.
Configure the fourth step to update incidents with their associated Salesforce Case IDs.
- Click in the Action field and select Update Record.
- In the Table Name field, enter
incident
. The sys id is automatically selected because it’s a required field. - Click Add Fields.
- In the search field, enter
salesforce
, select u salesforce case id, and then click Add. - Map the Incident fields to the preceding steps of the flow as follows.
- sys id = Sys_id from step 1
- u salesforce case id = Id from step 3
Create the fifth step for the flow to sync ServiceNow incidents with Slack notifications.
- Click the plus icon within the If branch to add a step.
- Click Slack.
- Click Add new Slack connection.
Note: If this is your first Slack connection, this option doesn’t appear. Go to the next step. - Name the connection
NTO Slack
and click Create. - Select NTO from the Slack workspace picklist.
- Click Allow to grant MuleSoft Composer the permissions to view content and info about channels and conversations, view content and info about your workspace, and perform actions in channels and conversations in the NTO workspace. The MuleSoft Platform app is automatically added to the NTO Slack workspace, and the fifth step of the flow appears.
Configure the fifth step to notify the service-cases channel of new incidents.
- Click in the Action field and select Post message to channel.
- In the Channel Name field, click the search picklist, select Pick from List, and then select service-cases.
- Click in the Message field and then click Custom Expression. The Custom Expression Editor opens. You use this Custom Expression Editor to configure a message that has both dynamic field values from the preceding steps of a flow and static text that you enter.
- In the Message field, enter
*New incident:*
. This uses Slack’s support for the Markdown syntax to turn *New incident:* into New incident: in Slack. - Insert a space and select Number from step 1 of the flow.
- Enter
,
and select Short_description from step 1 of the flow. - Click Apply.
- Leave the Bot Name and Bot Icon URL blank. By default, MuleSoft Composer uses the MuleSoft Platform Slack app to communicate with Slack.
Add an Else branch to the If/Else block of the flow to handle all incidents that have corresponding cases in Service Cloud.
- Click Add Else. Note that if the list of cases from the If branch isn’t empty, this means the incident has a corresponding case. So the next two steps in the Else branch (update Salesforce case and send Slack message) are executed.
Create the sixth step in the Else branch to update corresponding cases in Salesforce.
- Click the plus icon to add a step within the Else branch.
- Click Salesforce and then click NTO sandbox org.
Configure the sixth step to update corresponding cases in Salesforce.
- Click in the Action field and select Update record.
- In the Object Type field, enter
Case
. The Case ID is automatically selected because it’s a required field. - Click Add Fields, select Status and Subject, and then click Add.
- In the Record section, map the Case fields to their associated Incident fields in step 1 of the flow as follows.
- Case ID = U_salesforce_case_id from step 1
- Status = Escalated
- Subject = Short_description from step 1
Create the seventh step in the Else branch to sync ServiceNow incidents with Slack notifications.
- Click the plus icon within the Else branch to add a step.
- Click Slack and then click NTO Slack.
Configure the seventh step to notify the service-cases channel of updated incidents.
- Click in the Action field and select Post message to channel.
- In the Channel Name field, select service-cases.
- Click in the Message field and then click Custom Expression.
- In the Message field, enter
*Updated incident:*
. This turns *Updated incident:* into Updated incident: in Slack. - Insert a space and select Number from step 1 of the flow.
- Enter
,
and select Short_description from step 1 of the flow. - Click Apply.
- Leave the Bot Name and Bot Icon URL blank. By default, MuleSoft Composer uses the MuleSoft Platform Slack app to communicate with Slack.
- Save the flow. Your entire flow should look like this.
Good job! In the next unit, you learn how to test your flow to ensure it works as expected.