Outbound REST integration using flow designer
Before we had flow designer in servicenow, outbound integration with any other 3rd party tool was done by creating an outbound message and then creating a business rule to call that outbound message, which include lot of coding. This article will talk about how can you convert this configuration in a flow designer which needs less coding and hence more readable.
Pre-Requisites
You would need minimum two plugins in order to use REST APIs in flow designer.
1. IntegrationHub - This enables you to use REST step in flow designer Action.
2. ServiceNow IntegrationHub Enterprise Pack Installer - This lets you use dynamic inputs in flow designer.
Refer to this link for more details about integration plugins for flow designer.
Use Case
Existing
There are 2 servicenow instances ( in this case, I'll use 2 PDIs) and when incident is created on one instance ( Let's call it Source Instance A), same incident gets created in other instance , (lets call it Target Instance B). When incident is created in instance B, instance A gets the response and a field (in this case correlation_id , however you can use any other field ) on the incident form ( in instance A) gets populated with the incident number which is created in instance B. So correlation in instance A is the incident number of instance B.
New Requirement
When we update an incident in instance A , the corresponding incident number ( mentioned in correlation id) gets updated in instance B. For this example , we will update priority , state and short description from target instance A to source Instance B
Note: we will send the data via flow designer, however I am assuming that you already have a a scripted REST API /logic created in Target instance B which will accept the inputs we'll send from the flow designer. At the end, I'll give the snapshot of the logic I have defined in scripted rest API
Implementation
There are two parts to it.
1. Flow designer
2. Action
So the approach is that first create the action and then test it. Once it is tested successfully, this action can be called by a flow designer. Follow below steps to create action:
1. Navigate to Flow Designer > Designer in navigation pane.
2. you will get a new window. Click on Action and create a new action by clicking "New" button as shown below
3. Provide the name of the action and leave other details as it is and click submit.
Note: If you are working in any specific scope, make sure that is selected in "Application"
4. You'll get new screen as below where you can see inputs and outputs. In this case, inputs are "priority", "state" and "short description" which we need to update on instance B. Additionally you need to provide a lookup number ( in this case correlation id) which will define which incident to be updated in instance B
Note: My scripted rest API accepts correlation id in string parameter, however other inputs in the body of request. This may vary from case to case base don what configurations are you using
5. Now let's define inputs. So in this case there are 4 inputs ( correlation id, state, priority, short description) which need to be sent to Target instance B.
Click on create input on right hand side and create 4 input variables. No need to worry about the names. These need not be same as of backend names, however it will be good if you use similar names so that it is easy for you to understand later.
6. Save your work you have done so far. Click on the "+" sign you see in green color between Inputs and Outputs in left panel and select "REST" step under integrations. The step would be added and would look like below
7. Perform the configurations as below
Connection : "Define Connection Inline
Connection Alias : Select the + sign against this field , Select Basic auth credentials, and provide the details of the user who has access on the target instance B , select any available credentials alias and submit the user configuration
Base URL : Base url of third party tool. in this case it is servicenow so it will be something like https://devXXXXX.service-now.com
Resource path : Path of the scripted rest api to be called at target instance B . Example : /api/sn_hr_core/updateinchr
now in this case target is accepting "Correlation id" in path parameter so provide it here at the end. Click on the data pill against this field, select inputs > correlation id . It will look something like below
HTTP Method : PATCH ( as we are updating the record)
Headers: As this integration is from servicenow to servicenow, make the accept type as JSON, otherwise provide as per your requirement.
Request type : text
Request Body : Use data pill to pull all other three inputs in Json format as shown below
Note: Please make sure that you use same variable names which are being fetched at target.
8. Save the action and click on test
9. Check the execution logs. If it does not give any errors, it indicates that it ran fine. Also you can check at target instance if the incident got updated or not.
Note: if the required action is not performed on target instance, you might need to chec the logic in scripted rest api or business rule you have used at target instance.
Once the action is working fine, PUBLISH it . it will not work unless it is published
So our action is ready, however need to make the inputs dynamic for that we will create a flow and call this action from that flow . Follow below steps for the same :
1. Flow designer > Designer . On home page create new flow as shown below
2. Provide name and set Run as : "System Administrator" . click Submit
3. Provide trigger conditions based on your requirement. Here I am running it on update when correlation id is not empty . Once trigger conditions are complete. click Done.
4. Now click on next step > Action in the search box look for the action you created and select the action
5. Add the inputs dynamically using data pills as shown below. you need to dot walk to the required fields of incident you mentioned din the from trigger condition
After filling in all the inputs, it will look something like below
6. Click on done.
7. Save the Flow
8. Test the flow
9. Activate the flow.
This completed your integration of once instance with other instance using less coding and without using outbound message or business rule.
**********************************
Below is the snapshot of scripted rest api that I used on my target instance, however this will differ based on your requirements.
https://www.servicenow.com/community/developer-articles/outbound-rest-integration-using-flow-designer/ta-p/2308300