HR applications are often used by businesses to be the “system of record” or master data for employees to provide access to enterprise applications and services. So, it’s likely to store employee records in HR applications like SuccessFactors or BambooHR that would serve as a point of entry for an employee On-boarding business process which would then flow down to several consuming applications.
A use case for employee on-boarding
One such use case is to create an employee on the financial (or ERP) system to record employee expenses whenever a new employee is created on the system of record (HR system).
Mulesoft is a popular enterprise integration tool that enables data synchronization across the enterprise.
Let’s begin creating an integration using the Mulesoft Anypoint platform. Make sure you have their Integrated development environment (IDE) Mulesoft Anypoint Studio already installed.
REST End points
Lets assume the two systems that need to be synchronized already have REST web service interfaces. Here are two sample REST invocations on the source and the target systems:
HR System service (SOURCE System):
Http Method: GET path: /employees [Get all employees]
ERP System Service (TARGET System):
Http Method: GET path: /employee?empId=xx [Query employee based on empId]
This API call is used to retrieve the employee records from the target system to ensure an existing employee is not created inadvertently. We will assume that the target system’s REST API is not “idempotent”.
Http Method: POST path: /employee [Content-Type=application/json]
This API call is used to create the employee records on the target system
- Open Anypoint Studio
- Create a Mule Project and Mule Configuration file with name of “EmployeeSync”
- On the Global Mule Configuration Elements, Create Http Listener and Http Request configurations (Source and Target System) as per the below snippet. Make sure change the Host and Port.
The source view will display the following:
<http:request-config name="HTTP_Source_Request_Configuration" host="<Source_Host_name>"
port="<Soure_Port_name>" doc:name="HTTP_Source_Request_Configuration" >
<http:request-config name="HTTP_Target_Request_Configuration" host="<Target_host_name>"
port="<Target_port_name>" doc:name="HTTP Target Request Configuration"/>
- From the Mule palette, drag and drop the Flow scope to create a message flow called “CreateExpenseAtTgtSystem”
The source view should display the following:
<json:object-to-json-transformer doc:name="Object to JSON"/>
<http:request config-ref=" HTTP_Target_Request_Configuration " path="<URI of Target System>"
method="POST" doc:name="Call Create Employee REST API">
<logger level="INFO" doc:name="Log Response"/>
- From the Mule palette, drag and drop the Batch Scope to Create a Batch message flow called “Scheduled_Batch_Sync_Employee_Between_Two_Financial_System”.
- At “Input” section of Batch, Create Poll Scope and HTTP Request endpoint to call Source Financial System to Pull. The Poll Scope is used to schedule batch execution.
- Create DaveWeave Transform to convert source system employee to target system.
- Create JSON to Object Transform to Convert JSON pay load to java.util.Collection. Note: This is required because Batch Step “process record” section cannot iterate through JSON it.
- At the “Process Record” Section of Batch, create two Batch Steps, the first batch step to check whether target system contains the employee already, and second batch step is to create employee at target system.
- Batch 1: Batch_Step_Check_Employee_Availability_At_TargetSystem
- Back up the Employee Data to Flow variable
- Call Target System REST API to query employee with Source System Employee ID
- Convert JSON response to java.util.ArrayList. Note: this conversion is required because payload.size() method works only with java.util.ArrayList.
- Create Record variable “exists” and use the expression payload.size() > 0 to get Boolean value.
- Populate the Payload from back up as it was overridden by target employee query REST API. Note: I was unable to use Message Enricher as query to employee returns JSON and I could not check the payload size using size() method. The Message Enricher does not allow more than one flow object to add JSON to java.util.ArrayList.
- Batch 2: Batch_Create_New_Employee_At_TargetSystem
- This Batch scope has an Accept condition based on boolean record variable “exists”. This batch steps get executed only If “exists = false”.
- Call the Target system Create Employee REST API to create employee
Here is a screenshot of the resulting integration:
The Mulesoft Anypoint Platform empowers developers to build batch synchronization integrations pretty quickly and easily.