Consuming SAP HCM and AD
4E syncs data from various SAP modules (HCM) on a configured schedule
There are 2 main steps involved in syncing the SAP HCM data into 4E.
Sync SAP HCM data as a generic module into formSubmissionData collection.
Process the formSubmissionData – Map, save/update into 'users’ collection.
Step 1 - Sync SAP HCM data as a generic module
A sqs-queue-handler lambda function inside tqmi-sap repository connects to SAP OData service based on provided parameters. It syncs data from different SAP modules.
This handler handles 3 different types of messages (message type is passed into the request payload of sqs queue) –
GET_SAP_DATA
SAVE_SAP_DATA_INTO_FORM
UPDATE_SAP_DATA
There are multiple mongodb collections used to store SAP configuration data, which are –
sap_config – This collection has data related to different SAP module.
A document in this collection contains some information related to a specific SAP module. Below are some of the important fields -service_resource – url/endpoint of SAP module, used to connect with that specific module.
service_query_params – query parameters used to fileter the data
service_response_map – Mapping of SAP module fields to 4E fields.
dataCaptureFrequency – reference of dataCaptureFrequency document which contains SAP module data sync frequency schedule.
deltaTokenString – A token for delta sync up.
sap_form_connector – This is a mapping of sap_config and a form, also stores mapping of sap field to form field.
metricCollectionForms – This collection is used to store the forms related data. e.g., formElements, permissions (who can read, edit and fill the form). Also, some information on who created the form, form name and form data source.
metricCollectionFormsData – Has values of metrics in a form. Some important fields are metric key, value, label, UoM, submissionId, capture timestamp.
How does SAP HCM sync work?
Fetch the sap_config record using sapConfigId passed in the request payload. Also get the form for which data needs to be synced.
Connect to SAP ODATA service using endpoint, endpoint username and password provided in the request.
Update some information like – lastSyncTimestamp, deltaToken (if we get that in the response)
Go through the SAP response map and get the matching data to create/update record in mongodb collection.
Map form fields to SAP response and update push it into formSubmissionData.
If the call is for delta token change, then retrieve the matching record from mongodb formSubmissionData collection and update it. If the record is not present in collection, then create a new one.
Send the records for creation/updation to sqs queue with message type -SAVE_SAP_DATA_INTO_FORM
If it is an update record, then an event will be sent to update the SAP data (event event name UPDATE_SAP_DATA)
If sync fails, then sms and email notifications will be sent using notification templates.
SAVE_SAP_DATA_INTO_FORM – This handles the creation of new form submission data.
Once the forms data is updated, an event is sent to sqs queue to calculate/re-caculate the KPI actuals (event name - CALCULATE_KPI_ACTUALS_FOR_SAP_FORM_DATA)
UPDATE_SAP_DATA – This event handles the update of form data. After this operation also the same event is published to calculate the KPI actuals.
How to find configuration related to any module from sap_config collection?
Execute this query - {service_resource: {$regex: '/*module_name'}}
e.g. - {service_resource: {$regex: '/*HCM'}}
Step 2 - Process and save the users into ‘users’ collection
Once the user data is synced into formSubmissionData another handler processes that data, there is a handler sap-users-integration-handler from tqmi-user-api repository which handles the processing (mapping and storing) operations on raw SAP user data.
Below are steps which are performed by this handler –
Retrieve userDataForm from userDataForms collection.
Retrieve formSubmission data using the formId of the userDataForm retrieved in above step, which is nothing but the SAP users’ data.
An event COMPARE_FORM_RECORD_AND_UPDATE is raised for each record which compares an existing record and updates.
sqs-queue-handler.ts has a handler function which handles the above event. It gets all the existing users from ‘users’ collection.
Maps 4E fields with SAP fields
Compare all the fields of this user with existing user and updates only updated fields like department, supervisor etc.
Fields synced from SAP HCM module
SAP Field | 4E Field |
Employee Id | employeeId |
First Name | firstname |
Last Name | lastname |
Manager Id | supervisorId |
Employee Phone Number | mobile |
Employee Status | isActive |
Employee Mail Id | |
Employee Position | position |
Organization | department |
Business Area | city |
Sub Area | location |
LAST_UPDATED | 12 Oct 2021, Ajit |
---|---|
LAST_REVIEWED | 24 Oct 2021, Ameya |